Javascript XMLHttpRequests in Loop?

Posted by usurper on Stack Overflow See other posts from Stack Overflow or by usurper
Published on 2010-06-14T08:16:56Z Indexed on 2010/06/14 8:22 UTC
Read the original article Hit count: 200

Filed under:
|
|

Hi,

I am trying to save an array of records into a mysql database but I always get the abort message in firebug except for the last save. How do I save the records using a loop for XMLHttpRequest? Here is my code:

function savingContent() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();

} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

var rowindex = 0;

for (x in globalObj.AddedRows) { var rowData = "?q=" + globalObj.AddedRows[rowindex];

  xmlhttp.open("POST", "insertRowData.php"+rowData, true);
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
  xmlhttp.setRequestHeader("Content-Length",rowData.length); 
  xmlhttp.send(null);
  rowindex += 1;

}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about loop