I pasted your code in a mooshell and called the cancel method and its ok.  
As far as I know when you cancel the request it stops.  

You could try adding: "link: 'cancel'" to your options.
(but this would only matter if you made two concurrent requests)

But as far as I can see the cancel method works fine (firebug's output):
POST http://mootools.net/shell/ajax_html_echo/    Aborted

http://mootools.net/shell/6spkD/

This is speculation:
The only other thing I can think of making your load times take 5 seconds is
if the destination page has not completing loading and the synchronies call
to request is waiting for the page to complete before it can actually quit.
However, this does not make sense as the default for request method is
asynchronies. 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of WarpY
Sent: Wednesday, March 17, 2010 11:58 AM
To: MooTools Users
Subject: [Moo] Help with Request.cancel().

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!

Reply via email to