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);
}
}