Skip to content

Instantly share code, notes, and snippets.

@sonalkr132
Last active July 25, 2016 17:07
Show Gist options
  • Save sonalkr132/3fc6ebf7a409bbba0530240ffc5becff to your computer and use it in GitHub Desktop.
Save sonalkr132/3fc6ebf7a409bbba0530240ffc5becff to your computer and use it in GitHub Desktop.
used on blog
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
var url = 'https://rubygems.org/api/v1/gems/rails.json';
var xhr = createCORSRequest('GET', url);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment