Skip to content

Instantly share code, notes, and snippets.

@edwinm
Created November 11, 2009 15:22
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 edwinm/232021 to your computer and use it in GitHub Desktop.
Save edwinm/232021 to your computer and use it in GitHub Desktop.
Small AJAX function, only supports GET, no caching.
/**
* Very small Ajax function.
*
* Bugs: doesn't support POST, only GET.
*
* @param {String} url
* @param {Function} fn
*/
function fetchXML(url, fn){
var xmlHttp = null;
var prop = arguments[2] || 'responseXML';
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
try {
if (xmlHttp) {
xmlHttp.onreadystatechange = done;
xmlHttp.open('GET', url, true);
xmlHttp.send('');
}
} catch (e) {}
function done(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
fn(xmlHttp[prop]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment