Created
January 13, 2014 23:25
-
-
Save JohnKim/8410068 to your computer and use it in GitHub Desktop.
CROS Sample
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
function makeRequest(method, url, params, fnLoad) { | |
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 { | |
xhr = null; | |
} | |
if (!xhr) { | |
// TODO :: Do Error Process... | |
return; | |
}else{ | |
xhr.onload = function() { fnLoad(xhr); }; | |
xhr.onerror = function() { // TODO :: Do Error Process... }; | |
xhr.send(params); | |
} | |
} | |
// sample !! | |
makeRequest( | |
'GET', | |
'http://server.host:8080/get/ASDFVEEWQQWERQWERQWERQW', | |
'p1=ABCDE&p2=12345', | |
function (xhr) { | |
console.log(xhr); | |
console.log(xhr.response); // not working on IE !!! | |
console.log(xhr.responseText); // Is's the best, I supposed... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment