Javascript JQuery Ajax Get请求中的发送头
这是我的密码Javascript JQuery Ajax Get请求中的发送头,javascript,jquery,ajax,Javascript,Jquery,Ajax,这是我的密码 $.ajax(this.url, { type: "GET", //dataType: "json", beforeSend: function (xhr) { xhr.setRequestHeader("x-token", token) }, success: function (data) { console.log(data); },
$.ajax(this.url, {
type: "GET",
//dataType: "json",
beforeSend: function (xhr) {
xhr.setRequestHeader("x-token", token)
},
success: function (data) {
console.log(data);
},
error: function(){
console.log('error');
}
});
我无法通过该代码发送ajax请求。我还尝试了header:{“x-token”:token},以代替beforeSend:但它对我也不起作用。您可能的副本还必须解释您得到了什么样的错误(如果有),以及在
this.url中发生了什么。我得到了console.log('error'),在服务器中,头带有未定义的值。并且这个.url获得正确的url对于我的post请求来说工作正常。