Created
October 21, 2016 15:47
-
-
Save paitonic/ba8366e6a419fe57ce68aeae5242b9f4 to your computer and use it in GitHub Desktop.
Test CORS
This file contains hidden or 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
// 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