This is what i did to run my callback function sufficiently after the AJAX call had been made so the browser doesn't cancel it and without having to wait for the server to complete the resquest:
var cb = function(){
window.document.location.href="http://google.com";
}
$.ajax({
url: 'x.html',
complete: cb,
timeout: 100
});
Here the timeout makes sure that if my server doesn't repond in 100ms
, the callback
is executed. 100ms
also is sufficient time for the browser to send the request.
I experimented with status codes and finally ended up not using them. I found them to unreliable cross browser and for JSONP requests missing.