我放了以下脚本以防止离开页面同时处理步骤
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
JQObj.ajax({
type: "POST",
url: "<?php echo $this->url(array('controller'=>'question','action'=>'cleaSess'), 'default', true); ?>",
success: function(data){}
});
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
但是每次我收到默认警报消息而不是设置自定义警报消息时,
我想在最终用户单击“离开页面”按钮时调用 ajax 调用,但是在上面的脚本中,在单击离开按钮之前调用 ajax 调用,
当且仅当人们离开页面时,任何人都有想法或逻辑来调用 ajax。