0

I have two AJAX deferreds which, when both succeed, should result in a success message. Otherwise, if either fails, the error message should show. Reduced code:

var reqs = $.map(['file', 'db'], function(mode) {
    $.get(wspath(desyn.repo_id, 'revert', { mode: mode, path: path, version: ver }))
});

$.when(reqs[0], reqs[1]).then(
    function() { alert('success'); },
    function() { alert('error'); }
);

For debugging purposes, I force the first request to fail - on the server I'm throwing an internal 500 error. This is borne out in the network console. However, the success callback is executed nonetheless, not the fail callback.

As I understand it (and as described in the final example on the jQuery docs page), passing two functions to then() means the first is the success callback and the latter the fail callback. So what's up?

1 Answer 1

2

you should do return $.get(... to actually have the deferred objects in the array

Sign up to request clarification or add additional context in comments.

1 Comment

Oh god... did I really just do that? Face palm x 1,000,000. Thanks for pointing out my lac of attention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.