jQuery Ajax发布标头始终为空(Web API)

时间:2018-06-20 18:16:07

标签: jquery ajax null header token

我的ajax Get allways发送空标头,因此服务器返回401

这是我的Ajax Get:

q + I(q^2)

这是Mozilla Network的Request标头,

当我通过添加授权进行编辑时:承载+令牌服务器返回200

Telerik提琴手也返回200,

我收到401,因为ajax请求中的标头为空

 $.ajax({
        url: 'http://localhost:54381/Home/NavBar/',
        type: 'Get',
        crossDomain: true,
        // beforeSend: function (xhr) {
        //     xhr.setRequestHeader("Autthorization", ":6013e7dc-a00dTestTest");
        // },
        dataType: 'json',
        headers: {
            "accept": "application/json",

            'authorization':'Bearer '+ accessToken,
            'content-type': 'application/x-www-form-urlencoded',
            'Companyid':"asdjhkaskjdlaskjd" // For Test still showing null 
            },
            success: function (data) 
            {
            alert('Success');
               alert(data);
            },

            error: function (xhr, status, error) 
            {
            alert('error');
        }
    });

0 个答案:

没有答案