Created
November 11, 2009 15:22
-
-
Save edwinm/232021 to your computer and use it in GitHub Desktop.
Small AJAX function, only supports GET, no caching.
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
/** | |
* 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