Skip to content

Instantly share code, notes, and snippets.

@ir-g
Last active December 19, 2015 11:49
Show Gist options
  • Save ir-g/5950793 to your computer and use it in GitHub Desktop.
Save ir-g/5950793 to your computer and use it in GitHub Desktop.
PowerJSLibs - Shorter faster code
/* 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
}
}
}
/* 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