Bug Tracker

Modify

Ticket #10598 (closed enhancement: invalid)

Opened 20 months ago

Last modified 20 months ago

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

comment:1 Changed 20 months ago by Gray Zhang <otakustay@…>

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

comment:2 Changed 20 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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().

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.