sayedsohail Posted August 15, 2007 Share Posted August 15, 2007 Hi everyone, The function below is written by matt, i would like to see if phpfreeks could incorporate this inside the basic ajax example listed under this section. Morever, i would appreciate if someone suggest any improvements to this function for a real life application. Thanks var xmlreqs = new Array(); function CXMLReq(freed) { this.freed = freed; this.xmlhttp = false; if (window.XMLHttpRequest) { this.xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } } function xmlreqGET(url) { var pos = -1; for (var i=0; i<xmlreqs.length; i++) { if (xmlreqs[i].freed == 1) { pos = i; break; } } if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); } if (xmlreqs[pos].xmlhttp) { xmlreqs[pos].freed = 0; xmlreqs[pos].xmlhttp.open("GET",url,true); xmlreqs[pos].xmlhttp.onreadystatechange = function() { if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos); } } if (window.XMLHttpRequest) { xmlreqs[pos].xmlhttp.send(null); } else if (window.ActiveXObject) { xmlreqs[pos].xmlhttp.send(); } } } function xmlhttpChange(pos) { if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) { if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) { handle_response(xmlreqs[pos].xmlhttp.responseXML); } else { handle_error(); } xmlreqs[pos].freed = 1; } } Reference: http://www.drakware.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.