jquery - xmlhttp.send() within .each() sends only the last record -


I'm trying to teach myself some php and Ajax for a pet startup project - $$$ $ someone Real technical man :-) Anyway, this is the background. I have selected a data in the HTML table, when an submitted function is called in the update. To select the selected record (radio button) I loop through the table and call them the update line file, assign a row and loop through each line and send the record to add to the database when I have If there is a JavaScript alert statement then all records are added to the database. But if I comment the warning then only the final record is added. I have tried to add 3 seconds, 5 seconds delay in the loop.

Here is the code snippet - some variables are set out of this loop and there is no problem with the values. $ row.each (function () {var $ rowcells = $ (this) .find ('td'); // Divide the entire row into columns var name = $ rowcells Eq (0) .text (); // Name of the selected relationship name = $ rowcells.eq (1). Child (). Val (); // Relationship with person // warning ("I was here" Name); // When this alert is uncommented xmlhttp.open ("post", "profileupdate.php", true), all records are added; xmlhttp.setRequestHeader ("content type", "application / x-www-form - urlencoded "); Xmlhttp.send (" type = "+ type +" & amp; userid = "+ userid +" and userrelid = "+ userrelid +" and relationtype = "+ relationtype +" and timer Eat = "+ timeouttext";});

I think connecting one at a time would be expensive on DB's performance. I should change that argument anyway but in the interim it would be nice to know what is happening here. N

You are sending HTTP request server asynchronous ('true' second parameter xmlhttp.open). This means that the next item in the row overrides the previous one.

You can try:

  • using multiple xmlhttp objects (for each element of the array)
  • as the second parameter Use the 'false'
  • In the third case, only after the last one has completed (in 'onreadystatechange' handler) to process the next element

    Can not use every 'iterator.

    More info:

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -