开发者

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

开发者 https://www.devze.com 2023-01-01 06:41 出处:网络
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 th

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';
  开发者_StackOverflow社区  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);
})


success

From the jQuery site http://api.jquery.com/jQuery.ajax/

complete(XMLHttpRequest, textStatus)Function

A function to be called when the request finishes (after success and error callbacks are executed)...


"complete" fires after "success" or "failure"

0

精彩评论

暂无评论...
验证码 换一张
取 消