2017-02-20 2 views
0

Ich versuche auf Location Header der folgenden Ajax-Antwort zuzugreifen. Aber es gibt mir null. Mein JavaScript-Code ist,Fehler beim Abrufen des Standortheaders der Ajax-Anforderung?

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); 

Im Folgenden sind meine corrosponding Optionen und Post-Anfragen,

Option anfordern

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 

Option Antwort

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 

Beitrag anfordern

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; 

Beitrag Antwort

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 

Access-Control-Allow-Header & Access-Control-Expose-Header mit dem Wert richtigen Ort zur Verfügung stehen. Aber warum kann ich nicht auf Location header zugreifen?

+0

Bitte keine Bilder von Text enthalten; Gib einfach den Text ein. Sie sehen die Quellschaltfläche anzeigen? Klicken Sie darauf, kopieren Sie den Text und fügen Sie ihn in die Frage ein. –

+0

@Mike: Ich habe es geändert – maamaa

Antwort

1

Sie können nicht die Location-Header erhalten, weil der Browser transparent folgen, so die Antwort, die XHR Verarbeitung endet die nächste ein (die keine Location-Header haben wird).

+0

Kann ich den Redirect-Prozess nicht stoppen und den Standort-Header abrufen? – maamaa

Verwandte Themen