2011-02-02 31 views
0

我使用jQuery 1.5

function doAjax(){ 
     return $.get('ajax.php'); 
    } 

    function doMoreAjax(){ 
     return $.get('ajax.php'); 
    } 

    $.when(doAjax(), doMoreAjax()).then(function(){ 
     console.log('I fire once BOTH ajax requests have completed!'); 
    }).fail(function(){ 
     console.log('I fire if one or more requests failed.'); 
    }).success(function(){ 
     console.log('I fire if all requests success.'); //It not works for me 
    }) 

問題:我不能使用successerror功能與$.when因爲$。當或$就相同。

我可以使用successerror$.ajax爲什麼我不能用$.when

+0

我對這個問題感到困惑。你要多少個甜甜圈? – Jason 2011-02-02 05:00:51

回答

2

使用我覺得你有一個關於它的錯誤的觀念。

從文檔,

$.when(doAjax(), doMoreAjax()) 
    .then(myFunc, myFailure); 
// Execute the function myFunc when both ajax requests are successful, 
// or myFailure if either one has an error. 

,你可能想讀Deffered Object。我知道你會在控制檯Uncaught TypeError: Object #<an Object> has no method 'success'中得到這種錯誤,只是因爲​​返回Deffered Object