Modify ↓
Ticket #10598 (closed enhancement: invalid)
jXHR.done should be fired with setTimeout when xhr is in complete state
| Reported by: | Gray Zhang <otakustay@…> | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.6.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
How to produce
execute code below:
var xhr = $.get('some-resource');
setTimeout(function() {
var i = 1;
xhr.done(function() {
alert(i);
});
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
Comment
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.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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