javascript - window.onbeforeunload ajax request in Chrome -


i have web page handles remote control of machine through ajax. when user navigate away page, i'd automatically disconnect machine. here code:

window.onbeforeunload = function () {   bas_disconnect_only(); } 

the disconnection function send http request php server side script, actual work of disconnecting:

function bas_disconnect_only () {    var xhr = bas_send_request("req=10", function () {    }); } 

this works fine in firefox. chrome, ajax request not sent @ all. there unacceptable workaround: adding alert callback function:

function bas_disconnect_only () {    var xhr = bas_send_request("req=10", function () {      alert("you're been automatically disconnected.");    }); } 

after adding alert call, request sent successfully. can see, it's not work around @ all.

could tell me if achievable chrome? i'm doing looks legit me.

thanks,

i having same problem, chrome not sending ajax request server in window.unload event.

i able work if request synchronous. able jquery , setting async property false:

$(window).unload(function () {    $.ajax({      type: 'get',      async: false,      url: 'someurl.com?id=123'    }); }); 

the above code working me in ie9, chrome 19.0.1084.52 m, , firefox 12.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -