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 th
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
});
The best way to detect request abortion and avoiding false positive from offline mode :
$("#loading").ajaxError(function(event, xhr) {
if (xhr.status === 0) {
if (xhr.statusText === 'abort') {
// Has been aborted
} else {
// Offline mode
}
}
});
This is by design. Test if data
is null to determine if the request responded correctly.
If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method.
It may be useful to handle this (from here).
I found here that the xhr
will return with status 0
. Seems to be a jQuery 1.4+ bug. On 1.3 it called the error handler.