Posts

Showing posts from November 12, 2006

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.