Xillar Posted January 19, 2007 Share Posted January 19, 2007 Hello,( I'm dutch so my englisch is poor sorry :'( )I've got a Ajax script with a for loop.I want to make a new request from inside the for loop with a created onclickas result i get thisid 1id 2id 3i give this id with my onlick as you can see in my code below.but if i click on the link in my result table te output in the next function handle_fact is always 3.my code:for loop:[code]for ( i=0;i<results.length; i++){ var artId = result.getElementsByTagName("artId"); var artId = artId.item(i); var artId = artId.firstChild.nodeValue var artTr = document.createElement("tr"); var artaddTd = document.createElement("td"); artaddTd.className = "addTd"; artaddTd.innerHTML = artId; artaddTd.onclick = function() { make_request('mandje.php?id=' + artId, 'handle_fact', 'GET', null, true); } artTr.appendChild(artaddTd); artTbody.appendChild(artTr); artTable.appendChild(artTbody); artDiv.appendChild(artTable); suggestionDiv.appendChild(artTable); } [/code]result code handle_fact:[code]function handle_fact(result) { var productenDiv = document.getElementById("productenDiv"); var results = result.getElementsByTagName('result'); productenDiv.innerHTML = ''; for( ii=0; ii<results.length; ii++) { var test= result.getElementsByTagName("test"); var test = test.item(ii); productenDiv.innerHTML = test.firstChild.nodeValue; } } [/code] Quote Link to comment https://forums.phpfreaks.com/topic/34871-function-form-for-loop/ Share on other sites More sharing options...
bibby Posted January 22, 2007 Share Posted January 22, 2007 That's certainly going to break! You can't make requests that fast. Each one is going to listen for a ready state.If you had 1000 items, you'd make 1000 server requests in 10ms!Of course, it'll break by the second one.You should find a way to preallocate those values. Quote Link to comment https://forums.phpfreaks.com/topic/34871-function-form-for-loop/#findComment-165961 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.