Skip to content

Instantly share code, notes, and snippets.

@paitonic
Created October 21, 2016 15:47
Show Gist options
  • Save paitonic/ba8366e6a419fe57ce68aeae5242b9f4 to your computer and use it in GitHub Desktop.
Save paitonic/ba8366e6a419fe57ce68aeae5242b9f4 to your computer and use it in GitHub Desktop.
Test CORS
// http://www.test-cors.org/
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};
var url = '';
var method = '';
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
// Success code goes here.
};
xhr.onerror = function() {
// Error code goes here.
};
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment