Created
August 2, 2012 06:05
-
-
Save jpalala/3234283 to your computer and use it in GitHub Desktop.
ajax ahah library error
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 ahah(url, target) { | |
document.getElementById(target).innerHTML = ' Fetching data...'; | |
if (window.XMLHttpRequest) { | |
req = new XMLHttpRequest(); | |
} else if (window.ActiveXObject) { | |
req = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
if (req != undefined) { | |
req.onreadystatechange = function() {ahahDone(url, target);}; | |
req.open("GET", url, true); | |
req.send(""); | |
} | |
} | |
function ahahDone(url, target) { | |
if (req.readyState == 4) { // only if req is "loaded" | |
if (req.status == 200) { // only if "OK" | |
document.getElementById(target).innerHTML = req.responseText; | |
} else { | |
document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment