松江网站建设多少钱,wordpress显示缩略图,企业网站建设 ppt,如何做网站的源码场景#xff1a;在jquery封装的ajax请求中#xff0c;默认是异步请求。 需要定一个秘钥进行解密#xff0c;所以只能存放在请求头中。然后需要值的时候去请求头中读取。
注意#xff1a;dataType设置#xff0c;根据请求参数的格式设置#xff0c;如果是加密字符串…场景在jquery封装的ajax请求中默认是异步请求。 需要定一个秘钥进行解密所以只能存放在请求头中。然后需要值的时候去请求头中读取。
注意dataType设置根据请求参数的格式设置如果是加密字符串就设置为text如果是json,就设置为json,否则接口请求状态码是200但是会进入到error函数中。
$.ajax({url: url,data:{req:somedata},type:post,cache:false,dataType:json,//注headers:{key:bar}, //设置请求头success: function() {alert(this.headers.key);//获取请求头},error:function(){}
});目前到上面我的问题就解决了。 参考文章https://www.it1352.com/2772303.html 但是我认为只有已经在 headers 中定义的标题是可用的(不确定如果标题被改变会发生什么(例如在 beforeSend 中). 您可以在以下位置关于 jQuery ajax 的信息:http://api.jquery.com/jQuery.ajax/ 如果您只想捕获对 XMLHttpRequest 上的 setRequestHeader 的所有调用的标头那么您可以包装该方法.这有点麻烦当然您需要确保在任何请求发生之前运行包装下面的代码的函数.
// Reasign the existing setRequestHeader function to
// something else on the XMLHtttpRequest class
XMLHttpRequest.prototype.wrappedSetRequestHeader XMLHttpRequest.prototype.setRequestHeader; // Override the existing setRequestHeader function so that it stores the headers
XMLHttpRequest.prototype.setRequestHeader function(header, value) {// Call the wrappedSetRequestHeader function first // so we get exceptions if we are in an erronous state etc.this.wrappedSetRequestHeader(header, value);// Create a headers map if it does not existif(!this.headers) {this.headers {};}// Create a list for the header that if it does not existif(!this.headers[header]) {this.headers[header] [];}// Add the value to the headerthis.headers[header].push(value);
}现在一旦在 XMLHttpRequest 实例上设置了标头我们就可以通过检查 xhr.headers 例如
var xhr new XMLHttpRequest();
xhr.open(get, demo.cgi);
xhr.setRequestHeader(foo,bar);
alert(xhr.headers[foo][0]); // gives an alert with bar