Can't use success error function in $.when()
I am using 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
})
Question: I can't use success
and error
function with $.when
since $.when or $.ajax are same.
I c开发者_JS百科an use success
and error
with $.ajax
why I can't use with $.when
I think you got a wrong idea about it.
from the docs,
$.when(doAjax(), doMoreAjax())
.then(myFunc, myFailure);
// Execute the function myFunc when both ajax requests are successful,
// or myFailure if either one has an error.
and you might wanna read Deffered Object. I know you would get this kind of error in the console, Uncaught TypeError: Object #<an Object> has no method 'success'
, simply because .then()
returns a Deffered Object.
精彩评论