Last active
December 19, 2015 11:49
-
-
Save ir-g/5950793 to your computer and use it in GitHub Desktop.
PowerJSLibs
- Shorter faster code
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
/* Not mine: http://www.xfront.com/microformats/AHAH.html */ | |
function ahah(url, target, delay) { | |
var req; | |
document.getElementById(target).innerHTML = 'waiting...'; | |
if (window.XMLHttpRequest) { | |
req = new XMLHttpRequest(); | |
} else if (window.ActiveXObject) { | |
req = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
if (req != undefined) { | |
req.onreadystatechange = function() {ahahDone(req, url, target, delay);}; | |
req.open("GET", url, true); | |
req.send(""); | |
} | |
} | |
function ahahDone(req, url, target, delay) { | |
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.statusText; | |
} | |
if (delay != undefined) { | |
setTimeout("ahah(url,target,delay)", delay); // resubmit after delay | |
//server should ALSO delay before responding | |
} | |
} | |
} |
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
/* Do whatever you like with this, a link to me is nice! */ | |
function valueById(id){ | |
x = document.getElementById(id).value; | |
return(x); | |
}; | |
function changevalueById(id,content){ | |
x = document.getElementById(id).value; | |
x = content; | |
return(x); | |
}; | |
function contentByID(id){ | |
x = document.getElementById(id).innerHTML; | |
return(x); | |
}; | |
function changecontentById(id,content){ | |
x = document.getElementById(id).innerHTML; | |
x = content; | |
return(x); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment