jQuery ajax设置全局配置

$.ajaxSetup({
    dataType : "json",
    contentType : "application/json",
    headers : {
        'Content-Type' : 'application/x-www-form-urlencoded'
    },
    error : function(jqXHR, textStatus, errorThrown) {
        switch (jqXHR.status) {
        case (500):
            layer.alert('服务器系统内部错误', {
                icon : 2
            });
            break;
        case (401):
            layer.alert('未登录', {
                icon : 2
            });
            break;
        case (403):
            layer.alert('无权限执行此操作', {
                icon : 2
            });
            break;
        case (408):
            layer.alert('请求超时', {
                icon : 2
            });
            break;
        default:
            layer.alert('未知错误,请联系管理员', {
                icon : 2
            });
        }
    },
    cache : false
});
posted @ 2017-12-20 14:55  試毅-思伟  阅读(203)  评论(0编辑  收藏  举报