我尝试了here的所有建议,但获得了
xhr.getHeaderResponse('Location')中的null。以下是快速代码视图:
param.async = true;
param.xhrFields = { withCredentials: true };
param.crossDomain = true,
param.processData = false;
param.headers = {
"content-type":"application/json",
"cache-control": "no-cache",
}
var request = $.ajax(param);
request.done(function( result,status,xhr ){
console.log(xhr.getResponseHeader("Location"));
});
然而,运行url并通过检查请求参数,它会在响应标头中显示位置:
Cache-control: no-cache, no-store
Connection: keep-alive
Content-Length: 1403
Content-Type: text/html; charset=utf-8
Date: Wed, 23 May 2018 05:23:14 GMT
Location: https://accounts.google.com/o/oauth2/v2/auth?state=<my state code>&redirect_uri=<my redirect url>&prompt=select_account&response_type=code&client_id=<my client id>&scope=<my scope>&access_type=online
Server: nginx/1.4.6 (Ubuntu)
X-Content-Type-Options: nosniff
任何人都可以告诉我这个问题在哪里?
答案 0 :(得分:0)
这可能是CROS的一个问题,请尝试使用纯JavaScript进行相同的XHR调用
var xhr = new XMLHttpRequest();
xhr.open('GET', "http://example.com/redirect", true);
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(xhr.responseURL);
}
};
xhr.send();