var nowLoading = false; var requests = new Array(); function xmlhttpPost(strURL, strArgs, divId) { var xmlHttpReq = false; var self = this; // Mozilla/Safari if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } self.xmlHttpReq.open('POST', strURL, true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); if (divId == false) { self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { var responseText = self.xmlHttpReq.responseText; // self.nowLoading = false; // self.processRequests(); eval(responseText); // alert(self.xmlHttpReq.responseText); // document.write(self.xmlHttpReq.responseText); self.nowLoading = false; self.processRequests(); } } } else { self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { var responseText = self.xmlHttpReq.responseText; // self.nowLoading = false; // self.processRequests(); updatepage(responseText, divId); // alert(self.xmlHttpReq.responseText); // document.write(self.xmlHttpReq.responseText); self.nowLoading = false; self.processRequests(); } } } self.xmlHttpReq.send(strArgs); // document.getElementById(divId).innerHTML = "Loading..."; } function updatepage(str, divId){ document.getElementById(divId).innerHTML = str; } function insertTable(divId, replace, table, args) { if (replace) { for (var i=requests.length-1; i>=0; i--) { if (requests[i][0] == divId && requests[i][1] == table) { requests.splice(i, 1); } } } this.requests.push(new Array(divId, table, args)); this.processRequests(); } function processRequests() { if (!this.nowLoading) { if (this.requests.length > 0) { var request = this.requests.shift(); var divId = request[0]; var table = request[1]; var args = request[2]; this.nowLoading = true; xmlhttpPost('http://m.nieuwslijst.nl/js/req.php', 'type=' + table + '&' + args, divId); } } }