javascript - Redirect only after script Completes it's execution in codeigniter
I want to redirect to view with script in codeigniter. Script first and then page redirection.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function login()
{
$this->load->view('login');
}
}
I tried this code but it's not working because page is redirected before script completes it's executions. So, How to show notification in alert.
echo "<script>";
echo "alert('User not Found');";
echo "</script>";
redirect('home/login');
I tried with this also,
echo "<script>";
echo "alert('User not Found');";
echo "</script>";
echo "<script>setTimeout(\"location.href = 'http://localhost/dealsnow/index.php/home/login';\",300);</script>";
Second way is working for me but i think it's not good way. So is there any other option available for redirection to view after script completes it's execution. Example : If i insert Form Data and then I want to show user that data is inserted properly in script and then i want the page to redirect. Script first and then page redirection.
Answer
Solution:
Solve my question,
If we want to execute script first and then after some timeout. Ex. : if we want to show user that data is inserted properly in script and then i want the page to redirect.
Answer
Solution:
use flash data in your code.
Hope it will help.