我想在网页的unload函数中调用一个URL,但是在unload函数中,get请求无法工作。我的代码如下:
$(window).unload( function () {
jQuery.get("someurl")
} );
我们希望了解有关某些用户操作日志关闭窗口的信息。是否有可能做到这一点?
如果在jQuery.get()之后添加alert(),则Get-Request有足够的时间完成此操作,但这不是我们首选的方法。
我想在网页的unload函数中调用一个URL,但是在unload函数中,get请求无法工作。我的代码如下:
$(window).unload( function () {
jQuery.get("someurl")
} );
使用方法:
jQuery.ajax({url:"someurl", async:false})
window.onbeforeunload = function() {
var URL = 'someplace';
var request = null;
if (window.XMLHttpRequest){
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
if (request) {
request.open("GET", URL, false);
request.send();
}
}