-
-
Save duckinator/266616 to your computer and use it in GitHub Desktop.
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 loadDoc(url, callback) { | |
// branch for native XMLHttpRequest object | |
try { | |
if (window.XMLHttpRequest) { | |
req = new XMLHttpRequest(); | |
req.onreadystatechange = (function(){ processReqChange(req, callback); }) | |
req.open("GET", url, true); | |
req.send(null); | |
// branch for IE/Windows ActiveX version | |
} else if (window.ActiveXObject) { | |
isIE = true; | |
req = new ActiveXObject("Microsoft.XMLHTTP"); | |
if (req) { | |
req.onreadystatechange = (function(){ processReqChange(req, callback); }) | |
req.open("GET", url, true); | |
req.send(); | |
} | |
} | |
} catch (e) { | |
window[callback](e.message); | |
} | |
} | |
// handle onreadystatechange event of req object | |
function processReqChange(req, callback) { | |
// only if req shows "loaded" | |
if ( req.readyState == 4 ) { | |
if ( req.statusText == "OK" ) { | |
window[callback](req.responseText); | |
} else { | |
window[callback]("Error fetching data: " + req.statusText); | |
} | |
} | |
} | |
function upvote() { | |
//loadDoc(url_as_str, callback_as_str) | |
//loadDoc('./up', 'foo();'); | |
alert('YOU RANG?'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment