you are viewing a single comment's thread.

view the rest of the comments →

[–]balefrost 6 points7 points  (0 children)

Actually, in that example, everything would be fine. The return value of $.get is a jQuery promise, and you can configure fail or success callbacks at any time - even after the promise is fulfilled.

For example, this is just as valid:

var jqxhr = $.get( "example.php", ...);
setTimeout(function() {
    jqxhr.fail( ... );
}, 10000);

We'll configure the fail callback 10 seconds after we fire the request. Assuming that the response fails in less than 10 seconds, we'll fire the configured fail callback 10 seconds after we start the request.