這是我的代碼。我已經嘗試過,flush(); window_location ..但仍然失敗。我該怎麼辦?我還測試了$ result的值是否被傳遞,並沒有問題。唯一的問題是JavaScript沒有加載。我有這個編碼結構的其他代碼,但工作正常,並顯示加載前的JavaScript。在重定向之前加載JavaScript(CodeIgniter)
function accsettings()
{
$this->load->model('admin_model');
$result = $this->admin_model->accsettings();
if ($result==0)
{
echo '
<script type="text/javascript">
alert("Congratulations! Your profile has been updated.");
</script>
';
$res2 = $this->admin_model->accset_audit();
}
else if ($result==1)
{
echo '<script type="text/javascript"> alert("Error! Current password is not correct."); </script>';
}
else
{
echo '<script type="text/javascript"> alert("New password does not match with the confirmation."); </script>';
}
redirect('/main/accsettings');
}
這不會有任何效果。您首先打印一些輸出,然後將用戶發送到另一頁。出現錯誤時,您不應該重定向用戶。 – Jerodev 2014-09-23 09:28:49
@Jerodev,我在我的程序的其他功能上有這個確切的代碼,它工作。 – Retroswald13 2014-09-23 09:31:32