Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 无法获取ajax请求的位置标头?_Javascript_Ajax_Http - Fatal编程技术网

Javascript 无法获取ajax请求的位置标头?

Javascript 无法获取ajax请求的位置标头?,javascript,ajax,http,Javascript,Ajax,Http,我试图访问以下ajax响应的位置头。但它给了我零。我的javascript代码是 var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "http://localhost:8080/openam/oauth2/authorize", true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset

我试图访问以下ajax响应的位置头。但它给了我零。我的javascript代码是

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "http://localhost:8080/openam/oauth2/authorize", true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
    xmlhttp.withCredentials = true;

    xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
            if(this.readyState == this.HEADERS_RECEIVED) {
                alert(xmlhttp.getResponseHeader("Location"));
         }
    }

    xmlhttp.send(params);
以下是我的回复选项和帖子请求

选项请求

OPTIONS /openam/oauth2/authorize HTTP/1.1
Host: localhost:8080
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: POST
Access-Control-Request-Headers: cache-control
Origin: http://127.0.0.1:4000
Connection: keep-alive
选项响应

HTTP/1.1 200 
Access-Control-Allow-Origin: http://127.0.0.1:4000
access-control-allow-credentials: true
Access-Control-Max-Age: 10
Access-Control-Allow-Methods: POST

Access-Control-Allow-Headers: iplanetdirectorypro,cookie,origin,x-requested-with,access-control-request-headers,x-openam-password,content-type,location,x-openam-username,access-control-request-method,cache-control,accept

Content-Length: 0
Date: Mon, 20 Feb 2017 17:57:34 GMT
后请求

POST /openam/oauth2/authorize HTTP/1.1  
Host: localhost:8080 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cache-Control: no-cache 
Referer: http://127.0.0.1:4000/login.htm 
Content-Length: 139
Origin: http://127.0.0.1:4000
Cookie: amlbcookie=01; 
回复后

HTTP/1.1 302 
Access-Control-Allow-Origin: http://127.0.0.1:4000
access-control-allow-credentials: true
access-control-expose-headers: Access-Control-Allow-Origin,Access-Control-Allow-Credentials,Set-Cookie,Date,Location
Cache-Control: no-store
Date: Mon, 20 Feb 2017 17:57:34 GMT
Accept-Ranges: bytes
Location: http://localhost:8080?code=669b8303-d8cd-4e01-90ad-7cb89007fc65&scope=address%20openid%20profile%20email

访问控制允许标头和访问控制公开标头具有正确的位置值。但是为什么我不能访问位置头?

你不能获取位置头,因为浏览器将透明地跟随它,所以XHR最终处理的响应是下一个响应(没有位置头)。

我不能停止重定向过程并获取位置头吗?请不要包含文本图像;只包括文本。看到“查看源代码”按钮了吗?单击它,然后将该文本复制并粘贴到问题中。@Mike:我更改了它