Ajax 添加授权标头时的选项请求

Ajax 添加授权标头时的选项请求,ajax,header,Ajax,Header,这是我的问题,我试图将以下标题添加到我的GET ajax请求中: Authorization: Basic XXXXXXX 所以我写了这个: function() { var storage = window.localStorage; var currentUsername = storage.getItem("username"); var currentPassword = storage.getItem("password");

这是我的问题,我试图将以下标题添加到我的GET ajax请求中:

Authorization: Basic XXXXXXX
所以我写了这个:

    function() {
        var storage = window.localStorage;
        var currentUsername = storage.getItem("username");
        var currentPassword = storage.getItem("password");
        var auth = makeBasicAuth(currentUsername, currentPassword);
        $.ajaxSetup ({
            beforeSend: function(request) {
                request.setRequestHeader( "Authorization", auth );
            }
        });
我已经检查了auth的值是否正确。当我尝试发送请求时,我得到:

OPTIONS <myurl> Error 401
注意:无论我试图添加的标题是什么,我都会得到这个结果。 问题在哪里


谢谢^。

您的web服务器是否配置为接受HTTP动词
选项
?我刚刚问了负责此服务器的人,我正在等待他的回答。
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Access-Control-Request-He...    authorization
Access-Control-Request-Me...    GET
Connection  keep-alive
Host    <myhost>
Origin  null
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0 
Access-Control-Allow-Head...    Authorization
Access-Control-Allow-Meth...    *
Access-Control-Allow-Orig...    *
Access-Control-Max-Age  3628800
Connection  Keep-Alive
Content-Encoding    gzip
Content-Length  440
Content-Type    text/html;charset=utf-8
Date    Tue, 23 Jul 2013 13:00:58 GMT
Keep-Alive  timeout=15, max=100
Server  Apache-Coyote/1.1
Set-Cookie  JSESSIONID=03A48D00EA04DE16396824E804E914AC; Path=/...
Vary    Accept-Encoding
WWW-Authenticate    Basic realm="Name Of Your Realm"