Ajax调用添加自定义标头给出错误未授权401

时间:2013-12-17 17:48:54

标签: javascript jquery cross-browser cors

我正在创建一个应用程序并执行Ajax调用以进行身份​​验证。以下是Ajax请求。

$.ajax({
            cache: false,
            type: "POST",
            async: false,
            beforeSend: function (xhr){
                xhr.setRequestHeader("Authorization", authenticationRequestHeader);
            },
            url: Server + "/Authenticate",
            dataType: "json",
            data: requestData,
            contentType: "text/json; charset=UTF-8",            
            success : function(dr) {
                alert('Success');
                data = dr;
        },
        error : function(xhr) {
            alert("Error : "+JSON.stringify(xhr));
        }
        });

它是一个跨域调用,下面是请求和响应

Request URL:http://10.101.72.20/SurveyServices/SurveyService.svc/Authenticate
Request Method:OPTIONS
Status Code:401 Unauthorized

Request Headers

Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:es,en;q=0.8,en-US;q=0.6,hi;q=0.4
Access-Control-Request-Headers:accept, authorization, content-type
Access-Control-Request-Method:POST
Host:10.101.72.20
Origin:http://localhost:9090
Proxy-Connection:keep-alive
Referer:http://localhost:9090/InfantSurvey/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36


Response Headers

Access-Control-Allow-Headers:Content-Type, Accept, Authorization
Access-Control-Allow-Methods:GET, POST
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1728000
Cache-Control:no-cache, no-store
Connection:Keep-Alive
Connection:Proxy-Support
Content-Length:1293
Content-Type:text/html
Date:Tue, 17 Dec 2013 17:43:38 GMT
Expires:-1
Pragma:no-cache
Proxy-Support:Session-Based-Authentication
Server:Microsoft-IIS/7.5
Via:1.1 TCSUYSRVISA01
WWW-Authenticate:Basic Realm=site
X-Powered-By:ASP.NET

我在错误处理程序中收到网络错误以及控制台消息“401(未经授权)”

请帮帮我,因为它对我来说是个塞子。我正在测试crome和mozila

0 个答案:

没有答案