2010-05-29 105 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

「成功」 或 「失敗」