Skip to content

Instantly share code, notes, and snippets.

@JohnKim
Created January 13, 2014 23:25
Show Gist options
  • Save JohnKim/8410068 to your computer and use it in GitHub Desktop.
Save JohnKim/8410068 to your computer and use it in GitHub Desktop.
CROS Sample
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