Hello,
I'm trying to have a javascript alert, after a database interaction and before a page redirect (back to the same page, but displaying the updated data).
I thought having a pause before the redirect with usleep() might work, but it seems to ignore it. If I comment out the redirect it takes me to the controller page, where the alert pops up.
Any ideas?
Here's my code:
function connect () {
$client_id = $this->uri->segment(3);
$related_id = $this->uri->segment(5);
$related_name = $this->uri->segment(6);
$uri_segments= $this->session->userdata('segments');
$uri = base_url()."index.php".$uri_segments;
if (!$this->uri->segment(4)) {
$this->load->model('get_clients_model');
$data['records'] = $this->get_clients_model->getAllClients();
$this->load->view('clients_all_related',$data);
}
elseif ($this->uri->segment(4) == "add") {
$this->load->model('get_clients_model');
$data['record'] = $this->get_clients_model->getSingleClient($client_id,$related_id,$related_name);
echo "<script>javascript:alert('".$data['record']."');</script>";
usleep(2000000);
redirect($uri); // send back to previous page with updated related contact
}
}
The relevant part is in the elseif.
As a side note if anyone knows a better way to do this other than the alert, which is just showing a success / fail message, then that would also be welcome.
Thanks!