Last active
January 19, 2016 16:06
-
-
Save zolitch/ee0eceac85dbe837806d 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
//From test-cors.org | |
var createCORSRequest = function(method, url) { | |
var xhr = new XMLHttpRequest(); | |
if ("withCredentials" in xhr) { | |
// Most browsers. | |
xhr.open(method, url, true); | |
} else if (typeof XDomainRequest != "undefined") { | |
// IE8 & IE9 | |
xhr = new XDomainRequest(); | |
xhr.open(method, url); | |
} 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