Ajax请求.哪个回调首先完成或成功执行?

Gut*_*ter 9 javascript ajax jquery

我可能会发现这一点,但我会使用SO.在我的单元测试(qunit)中,我使用(asynchTest的asynchShould别名)测试.部分断言是等待请求的完成/成功.像这样:

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);
})
Run Code Online (Sandbox Code Playgroud)

Luc*_*ofi 11

来自jQuery网站http://api.jquery.com/jQuery.ajax/

完成(XMLHttpRequest,textStatus)函数

请求完成时要调用的函数(执行成功和错误回调后)...


zed*_*xff 6

"成功"或"失败"后的"完全"火灾