Last active
July 25, 2016 17:07
-
-
Save sonalkr132/3fc6ebf7a409bbba0530240ffc5becff to your computer and use it in GitHub Desktop.
used on blog
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
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