我已经尝试了所有建议的解决方案来解决此问题,但其中任何一个都无法真正起作用。 唯一有效但仅在页面刷新之后的代码是这样。
<script language="JavaScript">
window.onload=function(){
document.getElementById('refresh').onclick=function() {
window.onbeforeunload = null;
window.location.reload(); // replace with your code
}
window.onbeforeunload = function() {
$.ajax({
method : 'POST',
data : ({check2:'check'}),
url: "ajax.php"
});
}
}
问题是此代码仅在页面刷新后才会触发...
有什么解决办法吗?在JS / JQ中?