全局给ajax加请求头

  • Post author:
  • Post category:其他



$.ajaxSetup({
	beforeSend: function (xhr,e) {
		console.log("eeeeee2",e)
		if(e.type=='POST'||e.type=='PUT'||e.type=='post'||e.type=='put'){
			console.log('POSTPUT加密前2:', "key1加密前:", endBody + "1qaz@WSX", "key2加密前:" + url + "1qaz@WSX")
			xhr.setRequestHeader("key1", 1);
			xhr.setRequestHeader("key2", 2);
		}else{
			var body = e.data ?  e.data : ""
			var key2 = hex_md5(e.url+body+"1qaz@WSX")
			console.log('URLGET加密前2',e.url+body+"1qaz@WSX")
			xhr.setRequestHeader("key1", "");
			xhr.setRequestHeader("key2", key2);
		}
	},
    complete: function(xhr, textStatus) {
		console.log('textStatus2',xhr,textStatus)
		// console.log(this.url,this.data)
        if (textStatus == 'timeout') {
			layer.alert('服务器错误,请联系管理员!');
			layer.close();
        } else if (textStatus == "parsererror") {
			layer.alert('服务器错误,请联系管理员!');
			layer.close();
        }
    },
});



版权声明:本文为ingenuou_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。