simple AJAX
this is the AJAX implementation i use:
function jfetch(url,t,o) {it's short, it only checks for the transport (ActiveX or XHR) once, and it takes either an element id or a call back function. and, i can understand it.
var req = jfetch.xhr();
req.open("GET",url,true);
req.onreadystatechange = function() {
if(req.readyState == 4){
var rsp = req.responseText;
if(t.constructor == Function) return t.apply(o,[rsp]);
t = document.getElementById(t);
t[t.value ==undefined ? 'innerHTML': 'value'] = rsp;
req = null;
}
};
req.send(null);
}
jfetch.xhr =
(window.ActiveXObject)
? function(){ return new ActiveXObject("Microsoft.XMLHTTP"); }
: function(){ return new XMLHttpRequest()};
Comments