rhyspaterson Posted September 24, 2008 Share Posted September 24, 2008 Hey guys, Having trouble using a counter in a for loop with AJAX calls. Code below: for(var x = 0; x < allPrinters.length; x++){ $.ajax( { url : "/data/printer_data[x].xml", dataType : ($.browser.msie) ? "text" : "xml", success : function(data) { var xml; if (typeof data == "string") { xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.loadXML(data); } else { xml = data; } if(!xml.getElementsByTagName("array")){ alert("NULL!"); } // Returned data available in object "xml" var name = xml.getElementsByTagName("system.sysname.0")[0].childNodes[0].nodeValue; var type = xml.getElementsByTagName("25.3.2.1.3.1")[0].childNodes[0].nodeValue; type = removeDoubleQuotes(type); var consoleDisplay = xml.getElementsByTagName("43.16.5.1.2.1.1")[0].childNodes[0].nodeValue; consoleDisplay = removeDoubleQuotes(consoleDisplay); var row = document.createElement('TR'); tmp.appendChild(row); var container = document.createElement('TD'); // ---------------------------------------------------- container.innerHTML= x; // ---------------------------------------------------- row.appendChild(container); var container = document.createElement('TD'); container.setAttribute('class', 'lft'); container.innerHTML=name; row.appendChild(container); var container = document.createElement('TD'); container.innerHTML=type; row.appendChild(container); var container = document.createElement('TD'); container.innerHTML=consoleDisplay; row.appendChild(container); var container = document.createElement('TD'); container.innerHTML='Undefined'; row.appendChild(container); document.getElementById('writeroot').appendChild(newTable); // Run the TableSort script fdTableSort.init('generatedTable'); } }); } Say for example that allPrinters.length is 10. I get the table rows generated the correct amount of times (10), however container.innerHTML= x is always set to 10 in each of the rows - instead of 1, 2, 3, 4 ect.. for each row generated. The x variable works for /data/printer_data(x).xml (i.e opening printer_data1.xml then printer_data2.xml ect) but not for container.innerHTML= x. Any suggestions? Cheers, Rhys 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.