Javascript 如何根据.ajaxSuccess的结果调用特定的成功回调
道歉,如果这已经被问到了某种形式或形式,但我不能完全找到我想要实现的,所以这里开始 在这种情况下,对特定服务进行的任何AJAX调用都会返回两个属性,如下所示:Javascript 如何根据.ajaxSuccess的结果调用特定的成功回调,javascript,jquery,ajax,Javascript,Jquery,Ajax,道歉,如果这已经被问到了某种形式或形式,但我不能完全找到我想要实现的,所以这里开始 在这种情况下,对特定服务进行的任何AJAX调用都会返回两个属性,如下所示: // Success Response { error : null, success : [ { ... some data here ... }, { ... some data here ... } ] } // Error Response { error : [ { ...
// Success Response
{
error : null,
success : [
{ ... some data here ... },
{ ... some data here ... }
]
}
// Error Response
{
error : [
{ ... some errors here ... },
{ ... some errors here ... }
],
success : null
}
// Global Handler
$.ajaxSuccess( function (resp) {
if(resp.error !== null) {
/*
Call a global function for handling API errors
Prevent execution of AJAX callback
*/
apiHelper.doErrorValidation(resp.error);
} else {
// Execute specific success callback of the request function
}
});
// Specific Handler
$.ajax(function () {
url : 'theUrl',
success : function (resp) {
specificModule.specificFunction(resp.data);
}
});
如代码块注释中所述,如果resp.error!==null,但在特定的ajax调用中执行成功回调,否则?
console.log(resp.error)
之前,如果这不是一个详细的答案,也不是很有用。为什么这会达到我想要达到的目的?