[英]Is there a way to load a whole URL under the same domain before redirecting to a blank window to wait its loading using JavaScript?
[英]Load JavaScript before Redirecting (CodeIgniter)
這是我的代碼。 我已經嘗試過,flush(); window_location ..但仍然失敗。 我該怎么辦? 我還測試了$ result的值是否已通過並且可以。 唯一的問題是JavaScript無法加載。 我還有其他具有此編碼結構的代碼,但工作正常,並在加載前顯示了JavaScript。
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');
}
我不建議這種方式顯示“ JavaScript”警報消息,如果您想顯示驗證消息,請設置變量控制器並檢查視圖。
在您的代碼中,您正在使用header
位置方法來重定向未在瀏覽器中顯示結果的頁面。
請使用refresh
方法在瀏覽器上顯示緩沖結果
redirect('/main/accsettings', 'refresh');
//similar to
header( "refresh:0;url=/main/accsettings" );
當您希望執行此重定向時,也應該在javascript中進行重定向。
這是實現此目標的方法:
<script type="text/javascript">
alert("Error! Current password is not correct.");
setTimeout(function () {
window.location.href = "http://www.google.nl"; //will redirect to google.
}, 2000); //will call the function after 2 secs.
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.