Skip to content

Instantly share code, notes, and snippets.

@zolitch
Last active January 19, 2016 16:06
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 zolitch/ee0eceac85dbe837806d to your computer and use it in GitHub Desktop.
Save zolitch/ee0eceac85dbe837806d to your computer and use it in GitHub Desktop.
//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