Call Url Before Closing Of Browser Window
I want to call an URL in the unload-Function of a Webpage but in the unload-function the get request is not working. My code looks like this: $(window).unload( function () { jQ
Solution 1:
Use:-
jQuery.ajax({url:"someurl", async:false})
Solution 2:
You need to use the onbeforeunload event directly. In that event, you can fire off an ajax call. This is one place where jQuery isn't really helpful (yet). A couple notes:
Don't return anything from the onbeforeunload event or the browser will display a "are you sure you want to leave this page" popup to the user
If you make the ajax call sync, it will stall the page unloading while it is running. If you make it async, the page will change while the call is running (you just can't have javascript event handlers for that call). Since jQuery wires up event handlers, its ajax support isn't as useful here.
window.onbeforeunload = function() {
varURL = 'someplace';
var request = null;
if (window.XMLHttpRequest){
request = newXMLHttpRequest();
} elseif (window.ActiveXObject) {
request = newActiveXObject("Microsoft.XMLHTTP");
}
if (request) {
request.open("GET", URL, false);
request.send();
}
}
Post a Comment for "Call Url Before Closing Of Browser Window"