我正在使用带有POST方法的表单来应用会话,一旦表单提交,页面就会重新加载,并且屏幕上没有任何警报。
所以我使用了一些我在网上找到的技巧,但它有一个问题,在表单提交后弹出警报,但没有一个页面设计工作,这意味着我只有空白页和警报消息。
单击“确定”关闭警报消息后,页面将加载。
if(empty($_SESSION["shopping_cart"])) {
$_SESSION["shopping_cart"] = $cartArray;
$status = "Product is added to your cart!";
header('location:product.php?status=success');
}else{
$array_keys = array_keys($_SESSION["shopping_cart"]);
if(in_array($code,$array_keys)) {
$status = "Product is already added to your cart!";
header('location:product.php?status=failed');
} else {
$_SESSION["shopping_cart"] = array_merge($_SESSION["shopping_cart"],$cartArray);
$status = "Product is added to your cart!";
header('location:product.php?status=success');
}
}
// This right here responsible to alert the message according to the status.
if( $_GET['status'] == 'success') {
echo '<script> alert("welldone"); </script>';
}
else{
echo '<script> alert("no good"); </script>';
}
如何解决页面加载顺序,使页面首先加载,警报加载后?
翻阅古今
守着一只汪
慕姐4208626
人到中年有点甜