我正在寻找一种在成功回调中触发ajax错误的方法.我试图解释下面的问题代码:
$.ajax({ url: requestURL,data: postData,type: 'post',success: function(response){ if(response.Success){ // do something }else{ // request workflow fails in this case,// i have to trigger this ajax request's error callback } },error: function(){ // do something on error case },dataType: 'json' });
解决方法
var errorhandler = function(xhr,textStatus,error){ // do something on error case }; $.ajax({ url: requestURL,success: function(response){ if(response.Success){ // do something }else{ errorhandler(); } },error: errorhandler,dataType: 'json' });