javascript – Ajax请求.哪个回调执行完成或成功?

前端之家收集整理的这篇文章主要介绍了javascript – Ajax请求.哪个回调执行完成或成功?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以赶上这个来找出来,但是我要用SO.在我的单元测试(qunit)中,我使用asynchShould(别名asynchTest)测试.断言的一部分是等待请求的完成/成功.喜欢这个:
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);
})

解决方法

从jQuery网站 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)…

原文链接:https://www.f2er.com/ajax/151507.html

猜你在找的Ajax相关文章