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 <otakustay@gmail.com> | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.6.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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.
Attachments (0)
Change History (2)
Changed October 27, 2011 02:38PM UTC by comment:1
Changed October 27, 2011 09:47PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | new → closed |
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()
.
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