Skip to main content

Bug Tracker

Side navigation

#13171 closed bug (invalid)

Opened January 07, 2013 05:13PM UTC

Closed February 10, 2013 08:58AM UTC

Last modified July 01, 2013 05:46PM UTC


Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc: jaubourg
Blocked by: Blocking:

Ticket #12675 was closed as notabug, but it is definitely still a bug.

When an ajax request is in progress, and the user navigates away from the page, the error callback comes back with textStatus='error' and errorThrown="".

As promised in the documentation, the textStatus should be 'abort'.

Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror".
Attachments (0)
Change History (8)

Changed January 07, 2013 05:16PM UTC by comment:1

I agree

Changed January 26, 2013 08:57PM UTC by dmethvin comment:2

cc: → jaubourg
As promised in the documentation...

I am missing the sentence in the documentation that says, "If the browser terminates an outstanding AJAX request because the user navigated away from the page, jQuery promises the status will be "abort"."

jaubourg, is this even possible for us to do? I thought the "abort" came only from when the user called jQXHR.abort(). There's an onabort event on the XHR but we don't attach to it, most XHR docs don't mention it, and I don't know how cross-browser it is.

Changed January 26, 2013 09:14PM UTC by jaubourg comment:3

I'm puzzled by this one because it doesn't make sense unless some XHR implementations do call onreadystatechange when aborting on unload (prior to us attempting to do so in the oldIE cleanup of our own unload handler).

I'd love to see a use-case for this rather than the usual "me too"s. Is this for asynchronous requests or synchronous ones? Both? All browsers? Just Chrome? Just in an extension?

Like Dave said, the "abort" status is only guaranteed for requests aborted using jqXHR.abort(). You can even change its value: jqXHR.abort("myStatus"); will have the status set to myStatus (this is how timeout handles it).

I'm more than willing to look at this but we have actually been given very few information.

Changed January 27, 2013 01:11AM UTC by dmethvin comment:4

owner: → anonymous
status: newpending

To the requester(s), please provide some more information about use cases.

Changed February 10, 2013 08:58AM UTC by trac-o-bot comment:5

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Changed February 13, 2013 02:52PM UTC by russ0519 comment:6

The use case is this. User navigates away from the page during an ajax request, and we want to know this in the failure function.

Right now I am using

if(textStatus == 'abort' || jqXHR.status==0){

which seems to work, but not clear if that's the right thing to do. From the documentation on .ajax:

Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror".

Which seems to suggest that if the ajax request is aborted (such as due to the user navigating away), the textStatus will be abort. If that is not the case, the documentation should be updated, and it should be made clear what the each status represents.

Changed February 13, 2013 02:54PM UTC by russ0519 comment:7

The preceding code should be

if(textStatus == 'abort' || jqXHR.status==0)

Changed July 01, 2013 05:46PM UTC by comment:8


Recently I needed to make a queue that is updated via ajax.

It is updated recursively with a interval between each request.

Users complained that they were receiving an error message when accessed any link while the queue is updated.

So I needed to identify if the onError was called by a failure or because the user left navigation during the ajax request.

I fulfilled using the combination of $.ajaxError and $.bind('beforeunload', func) in the following code

But I just tested in Chrome 27, IE 10 and Firefox, so I'm afraid because I do not know if implementation of beforeunload is ok in all major browsers.

Should be fine if $.ajaxError tell us if user left navigation.