【发布时间】:2017-05-20 10:07:05
【问题描述】:
update.php 页面
if (isset($_POST['bags']))
{
$bagS=$_POST['bags'];
$id=$_POST["id"];
$_SESSION['id']=$id;
$cats = explode(" ", $bagS);
$cats = preg_split('/,/', $bagS, -1, PREG_SPLIT_NO_EMPTY);
foreach($cats as $key => $cat )
{
$cat = mysqli_real_escape_string($con,$cats[$key]);
$cat = trim($cat);
if($cat !=NULL)
{
$stmt = $con->prepare('UPDATE wallet SET `Status`="Hold" where `Id`=? AND `bags`="'.$cat.'" ');
$stmt->bind_param("s", $_POST["id"]);
$stmt->execute();
}
}
}
想在window.onbeforeunload的index.php页面上使用update.php文件
在这里使用 ajax
function myfoo(){
$.ajax({
url: "update.php",
dataType: 'json',
data: {id: 1},
success: function (r) {}
});
}
window.onbeforeunload = function(){
myfoo();
return 'Are you sure you want to leave?';
};
【问题讨论】:
-
你的代码有什么问题?您面临的问题在哪里?
-
如果浏览器关闭或用户单击返回按钮,我想执行更新查询。我正在使用 update.php 和 index.php 文件。所以当 window.onbeforeunload 触发时如何在 index.php 上调用 update.php 文件
标签: php ajax onbeforeunload