Alex Rivera | Logout

How to detect if a request was aborted?

Asked 2010-09-05T23:51:18.240
38

I am making a request and then right after it I abort.

var x = $.get(url, function (d, e, xhr) { alert(d); });
x.abort();

The problem is that it executes the success function and returns empty data... (example here)

Is there a jQuery method to abort? or Is there a way to check if the xhr was aborted?

Edit
Report

1 Answer

4

EDIT: Try this:

x.onreadystatechange = null;
x.abort();

Seems to work. Not sure what side effects, if any.


Original answer:

Would it be sufficient to just test the response received?

var x = $.get("./", function (d, e, xhr) {
    if(d) {
        // run your code with response
        alert(d);
    }
    // otherwise, nothing will happen
});
answered 2010-09-05T23:59:03.473

Your Answer