2010-05-29 96 views
9

我可以通过这个来找出答案,但我打算使用它。在我的单元测试(qunit)中,我使用asynchShould(别名asynchTest)测试。部分断言是等待请求的完成/成功。就像这样:Ajax请求。哪个回调首先执行完成或成功?

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); 
}) 

回答

11

从jQuery网站http://api.jquery.com/jQuery.ajax/

完成(XMLHttpRequest的, textStatus)功能后, “完成” 火灾

当请求结束时调用的函数为 (在succ之后ess和错误回调是 执行)...

+0

我不记得有多少次,我读过该页,并没有看到它。 – Gutzofter 2010-05-29 18:25:51

6

“成功” 或 “失败”

相关问题