Skip to main content

Bug Tracker

Side navigation

#10598 closed enhancement (invalid)

Opened October 27, 2011 02:27PM UTC

Closed October 27, 2011 09:47PM UTC

jXHR.done should be fired with setTimeout when xhr is in complete state

Reported by: Gray Zhang <> Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

How to produce

execute code below:

var xhr = $.get('some-resource');
setTimeout(function() {
    var i = 1;
    xhr.done(function() {
    var i = 2;
}, 500);

What is expected

Since $.get is processed asynchronously, the line var i = 2; should be executed before the alert, so it should alert ''2''

What is the result

If server responses within 500ms, it alerts ''1'', otherwise it alerts ''2''


This would cause confusion, the same code may emmit different result due to different network latency, so I recommend all callbacks registered to the jXHR object fires with a setTimeout to simulate the async nature of common XMLHttpRequest control flow.

Attachments (0)
Change History (2)

Changed October 27, 2011 02:38PM UTC by Gray Zhang <> comment:1

Though the documentation said ''If the request is already complete, the callback is fired immediately'', but I preferrer it being changed to produce exactly same result for either condition

Changed October 27, 2011 09:47PM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed
I preferrer it being changed

We'd need to change the documented interface, so no, sorry. If you need the var i=2 code to always execute after the first .done(), add it in a second .done().