Ajax request. Which callback is executed first complete or success?

Posted by Gutzofter on Stack Overflow See other posts from Stack Overflow or by Gutzofter
Published on 2010-05-29T17:31:19Z Indexed on 2010/05/29 17:42 UTC
Read the original article Hit count: 160

Filed under:
|
|

I could spike this to find out, but I'm going to use SO. In my unit tests (qunit) I use the asynchShould (alias for asynchTest) test. Part of the assertion is to wait for the completion/success of the request. Like this:

asyncShould('talk to customer list server', 1, function() {
    stop(2000);
    var forCustomerList = newCustomerListRequest();

    forCustomerList.page = 'helpers/helper.php';
    forCustomerList.data += '&action=customerListServer&DB=11001';
    var originalSuccess = forCustomerList.success;

    forCustomerList.success = function(msg) {
        if (msg.flash !== undefined && msg.data !== undefined && msg.status !== undefined) {
            ok(true, 'json structure correct')
        }
        else {
            ok(false, 'json structure not correct');
        }
        originalSuccess(msg);
        start();
    };

    testController.getServerData(forCustomerList);
})

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery