Hi,
I'm fairly new to web development and JavaScript in general.
I am trying to build this MooTools script where I fire a
Request.send() and it goes out and fetches data from certain URLs.
Doing this takes the function 5+ seconds to complete. So, when I
unload the web page, I want to fire a Request.cancel() method to stop
fetching data from those URLs.
var r = new Request( {
method : 'get',
url : someurl,
onRequest : function() {
window.addEvent('beforeunload', function() {
r.cancel();
});
},
onCancel : function() {
alert('Ok, cancelling.');
},
onComplete : function(response) {
alert(response);
}
}).send();
Above is the code which I'm using.
The problem: When I try reloading the page (while the request is still
active) in order to fire the cancel method, it does the cancel and
sends me the alert (look at code) as well. But, the script still takes
the accounted 5+ seconds to operate and once it's done, my page
reloads. I do not want this to happen and want the script to die
completely so that I can reload instantly. Please help.
PS: If anything needs clarification please say so. I'm new to these
forums.
Thank you!