自定义Jquery:ajax,get,post方法

var myAjax = {
request: function(url, type, data, callback) {
$.ajax(url, {
type: type,
data: data,
cache: false,
success: callback,
statusCode: {
401: function() {
alert("未登录");
},
},
error: function(jqXHR, textStatus, error) {
switch (jqXHR.status) {
case 401:
alert("未登录");
break;
case 403:
alert("无权限");
break;
case 400:
case 409:
callback(jqXHR.responseJSON);
break;
default:
callback(jqXHR.responseJSON);
break;
}
}
});
},
get: function(url, data, callback) {
this.request(url, 'GET', data, callback);
},
post: function(url, data, callback) {
this.request(url, 'POST', data, callback);
}
}

posted @ 2014-09-24 11:25  hasayaki  阅读(235)  评论(0编辑  收藏  举报