一旦将值提交到 php 中的数据库,我就有以下代码重定向到同一页面。在重定向之前,它必须打印 js 警报,表明该值已提交。使用下面的代码,它只是重定向,但不打印警报。请告诉我代码中的问题出在哪里。
if ($runsql)
{
do_alert ("Profile for ".$student_pet_name." Saved Successfully");
header('Location: student_detail_entry.php');
}
else
{
echo "Error in Submitted Value ". mysql_error();
}
我的 do_alert 函数是
function do_alert($msg)
{
echo '<script type="text/javascript">alert("' . $msg . '"); </script>';
}
谢谢...
最佳答案
如果使用 header() 函数进行重定向,浏览器将立即重定向,并且不会向浏览器输出其他数据。
您可以先使用alert()并使用javascript执行重定向,例如与
window.location = "http://www.google.com/"
了解有关 header() 函数的更多信息:PHP.net header()
关于php - 重定向到标题而不在php中打印js警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17441562/