你可以你cookie和返回后只检查是否有指定cookie或没有,如果有,显示消息。
但是如果你使用ajax你不需要一个cookie,只需添加弹出功能阿贾克斯解析功能,这样的事情
function addToBasket(itemId) {
var x = new XMLHttpRequest();
x.open('GET', '/ajax/action.php?add=' + itemId, true);
x.onreadystatechange = function() {
if (x.readyState == 4) && (x.status == "200") {
var responseObj = eval('(' + x.responseText + ')');
if (responseObj.status == 0)
window.alert('The product successfully added to your basket');
else
window.alert('An error has occured during the processing the data. Please try again later');
}
};
x.send(null);
action.php代码示例
// ...
$response = array('status' => 1);
if (isset($_GET['itemId'] && $_GET['itemId'] != '')
{
$item_id = htmlspecialchars($_GET['itemId']);
if (is_numeric($item_id)
{
put_in_table($item_id);
$response = array('status' => 0);
}
}
// output an Ajax response
header('Content-Type: application/javascript');
echo json_encode($response);
?>