Last active
June 11, 2020 22:17
-
-
Save jamchamb/c88a79e8b1dcc2ca020e8b402c0bf2a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>CORS Test</title> | |
</head> | |
<body> | |
<script> | |
var xhr = new XMLHttpRequest(); | |
xhr.open( | |
"GET", | |
"https://URLHERE!", | |
true); | |
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers | |
// Access-Control-Allow-Headers: <header-name>[, <header-name>]* | |
xhr.setRequestHeader("Header", "value") | |
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials | |
// Access-Control-Allow-Credentials: true | |
xhr.withCredentials = true; | |
xhr.onload = function () { | |
console.log(xhr.responseText); | |
let jsonData = JSON.parse(xhr.responseText); | |
document.writeln("response:<br><pre>" + | |
JSON.stringify(jsonData, null, 4) + | |
"</pre>"); | |
}; | |
xhr.send(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment