Forum Moderators: open
I have a huge problem. I do not wan to use synchronous methods, because it will hang up the client machine. So asynchronous mode is needed.
I have checkboxes on a page. When clicking on a checkbox, a script fires, that will make an ajax call. It works like a charm if I click them one after other. But If I use the same ajax call in "batch" mode it will screw up everything.
HEre is the code - the usual javax stuff. If I click on a checkbox, problematic('chekbox_id'); is called. Http request is done, it is fine. If I use the selectAll function - which will go through one-by one on the checkboxes, and calls problematic('chekbox_id') function for each of them. The problem comes here. It handles the http requests just for some of the checkboxes. If I put an alert in the postRequest function - it stops the program for a second, and everything is fine. But if there is no alert, then everything is crashed. Even if I put some pause instead of alert.
Does anybody have any idea, what to do with it? I hope that the problem is clear...
Gergo
function createRequestObject() {
var oRequest;
var browser = navigator.appName;
if(browser == 'Microsoft Internet Explorer'){
oRequest = new ActiveXObject('Microsoft.XMLHTTP');
}else{
oRequest = new XMLHttpRequest();
}
return oRequest;
}
var http = createRequestObject();
var sPostedParameters = '';
function postRequest(){
//alert('If I put an alert here, everything is fine');
try{
http.open('POST', '#*$!.php');
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
http.onreadystatechange = handleResponse;
http.send(sPostedParameters);
} catch(oError){
sText="There was an error on this page.\n\n";
sText+="Error description: " + oError.description + "\n\n";
sText+="Click OK to continue.\n\n";
alert(sText);
} finally{}
}
function handleResponse() {
if(http.readyState == 4){
sResponse = http.responseText;
document.getElementById('the_place_where_I_show').innerHTML = sResponse;
}
}
function selectAll(){
aCheckBoxes = oTable.getElementsByTagName('input');
iNumberOfIdCheckboxes = aCheckBoxes.length;
for (i=0;i< iNumberOfIdCheckboxes;i++){
if(aCheckBoxes[i].type == "checkbox"){
problematic (i)
}
}
}
function problematic(param1){
sPostedParameters = 'param1='+param1;
postRequest();
}