simple AJAX

this is the AJAX implementation i use:

function jfetch(url,t,o) {
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()};
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.

Comments

Popular posts from this blog

filtering paired end reads (high throughput sequencing)

python interval tree

needleman-wunsch global sequence alignment -- updates and optimizations to nwalign