PDA

View Full Version : Multiple http request and show out the loading msg to user.



CstAn
Jun 26th, 2007, 06:11 PM
Dear all,

I had function that use AJAX to validate data with database. The problem is, how can i create multiple AJAX request to server and show the status to user?

current in my coding i cant get back the result and show if i run my application in internet but not problem with same local network & localhost. (this was depend on network traffic)

for example:
call function 1 then tell user current run function 1
then
call function 2 then tell user current run function 2
n etc......

my code:


//for display loading status
var BatchQueue = new function(){
var functions = new Array();

this.add = function(){
var object = arguments[0];
var actualArguments = new Array();
for(var i = 1; i < arguments.length; i++)
actualArguments.push(arguments[i]);
functions.push({object:object, arguments:actualArguments});
}

this.next = function(){
if(functions.length > 0){
var nextFunction = functions.shift();
nextFunction.object.apply(null, nextFunction.arguments);
setTimeout("BatchQueue.next()", 500);
}
}

this.start = function(){
setTimeout("BatchQueue.next()", 0);
}
};





for(i = 1; i <= totalCountRecord; ++i){
BatchQueue.add(checkOutStanding, i);
BatchQueue.add(chkFrt, i);
BatchQueue.add(validateDateInput, i);
}

BatchQueue.add(finalSubmitData, i);
BatchQueue.start();





function checkOutStanding(num){
clearTimeout(globalTimeOutId);
xmlHttp = createXmlHttpRequestObject();

if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){

var values = new Object();

values.idValue = eval("document.iframeShow.tempForm.compDetailId_"+num+".value");
values.type = 11;
values.getValue = eval("document.iframeShow.tempForm.qty_"+num+".value");
document.getElementById("currentRow").value = num;
// Encode POST data
var data = '';
for (var i in values) {
data += (data?'&':'')+i+'='+encodeURIComponent(values[i]);
}

url = "inc/queryForAJAX2.php";

xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader ('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
// define the method to handle server responses
xmlHttp.onreadystatechange = handleServerResponseForCheckOutStanding;
// make the server request
xmlHttp.send(data);
}else{
// if the connection is busy, try again after one second
globalTimeOutId = setTimeout("checkOutStanding("+num+")", 1000);
}
}



or can anyone guide me to create a validate input box with value in database and show out to user current which input box was checking?

thanks.