ajax的重写

$.najax = function (options) {
var opts = $.extend({
alerterror: true, alertbierror: true, cache: false, dataType: "json"
}, options);
//alertbierror:配置‘return Error()’时是否自动提示错误消息。默认true会提示消息
opts.success = function (data, st, xhr) {
if (opts.alerterror) {
if (!$.xhrSuccessDataExCheckHandle(data, opts.alertbierror)) {
if (options.errorCallback) {
options.errorCallback(data, st, xhr); //一般是处理服务器‘return Error()’
}
return false;
}
}
//else 和ajax无区别
if (options.success) { //除 服务器‘return Error()’外, 都会进来
if (!(options.loading === false) || options.loadingtext) {
$.loading(false);
}
options.success(data, st, xhr);
}
}
if (!(options.loading === false) || options.loadingtext) {
$.loading(true, options.loadingtext);
opts.error = function (XMLHttpRequest, textStatus, errorThrown) {
$.loading(false);
$.modalMsg(errorThrown, "error");
if (options.error) {
options.error(XMLHttpRequest, textStatus, errorThrown);
}
};
opts.complete = function () {
$.loading(false);
if (options.complete) {
options.complete();
}
};
}
$.ajax(opts);
}

猜你喜欢

转载自www.cnblogs.com/an123orange/p/10360994.html