我可以点击它来找出答案,但我将使用 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)...
关于javascript - Ajax 请求。哪个回调先执行完成或成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2935983/