Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#13171 closed bug (invalid)


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".

Change History (8)

comment:1 Changed 11 years ago by jquery@…

I agree

comment:2 Changed 11 years ago by dmethvin

Cc: jaubourg added

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.

comment:3 Changed 11 years ago by jaubourg

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.

comment:4 Changed 11 years ago by dmethvin

Owner: set to anonymous
Status: newpending

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

comment:5 Changed 11 years ago by trac-o-bot

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!

comment:6 Changed 11 years ago by russ0519

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'

which seems to work, but not clear if that's the right thing to do. From the documentation on .ajax: http://api.jquery.com/jQuery.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.

comment:7 Changed 11 years ago by russ0519

The preceding code should be

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

comment:8 Changed 10 years ago by lucas@…


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 http://jsfiddle.net/7A6Ne/

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.

Note: See TracTickets for help on using tickets.