Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery Ajax Get请求中的发送头_Javascript_Jquery_Ajax - Fatal编程技术网

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请求来说工作正常。