// ajax封装
function commonAjax(params) {
var ua = navigator.userAgent.toLowerCase();
var isIE = ua.indexOf("msie")>-1;
if(isIE) {
jQuery.support.cors = true;
}
$.ajax({
url: params.url,
type: params.type || 'POST',
traditional: true,
async: params.async || true,
dataType: params.dataType || 'json',
data: params.data,
contentType: params.contentType || "application/x-www-form-urlencoded",
xhrFields: { withCredentials: true },
crossDomain: true,
beforeSend: function(request) {
var token = $.cookie('token');
request.setRequestHeader("Authorization", token);
},
success: function(res, status, xhr) {
// console.log(xhr.getResponseHeader('content-type'));
if(res) {
params.success && typeof params.success == 'function' ? params.success(res) : ''
}
// 设置超时重新登录
if(res.code == 700){
clearAllCookie()
window.parent.location.href="/html/login.html"
}
},
error: function(error) {
if(params.error) {
params.error(error)
}
layer.closeAll()
layer.msg('系统繁忙,请稍后再试',{time:1000,icon:2,shade:0.1})
},
complete: function(xhr, status){
// xhr.getResponseHeader('sessionstatus') ? location.href = '/html/login.html' : '';
}
})
}