浏览器关闭后从数据库中删除 [英] delete from database after browser close
本文介绍了浏览器关闭后从数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发电子商务应用程序.但问题是当用户将产品添加到购物车并在订购前关闭浏览器时,购物车会带走所有产品.所有购物车项目都保存在一个表格中.
I am developing an E-Commerce application. But the problem is when user adds a product to cart and close the browser before order, the cart takes all the products. All the cart items are saved in a table.
如果用户没有订购就关闭浏览器,我只想刷新购物车.
I just want to flush the cart if the user closes the browser without ordering.
推荐答案
您可以使用 Javascript 事件来捕获浏览器关闭并向某些将删除购物车数据的脚本发送 ajax 请求:
You can use Javascript event to catch browser close and sent ajax request to some script that will delete cart data:
更新
<script language="javascript">
function fnUnloadHandler() {
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.open("GET","http://yourhost/del_cart_actionFile.php",true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
</script>
<body onbeforeunload="fnUnloadHandler()">
</body>
这篇关于浏览器关闭后从数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文