Skip to content

Instantly share code, notes, and snippets.

@jamchamb
Last active June 11, 2020 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamchamb/c88a79e8b1dcc2ca020e8b402c0bf2a6 to your computer and use it in GitHub Desktop.
Save jamchamb/c88a79e8b1dcc2ca020e8b402c0bf2a6 to your computer and use it in GitHub Desktop.
<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