Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery AJAX each problem
    text
    copied!<p>I am using jquery and i have script as below;</p> <pre><code>$(document).ready( function() { $('.nm').each(function(row) { $.ajax({ type: 'POST', url: 'test.php', data: 'id=' + 1, dataType: 'json', cache: false, success: function(result) { $('.title').each(function(index){ if (result) { $(this).html(result[index]); } else { $(this).html("&amp;nbsp;"); } }); }, }); }); }); </code></pre> <p>The script is suppose to change text in my table;</p> <pre><code>&lt;tr class="nm" style="height: 30px"&gt; &lt;td style="width: 15px;"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="section" colspan="5"&gt;Mix&lt;/td&gt; &lt;td style="width: 15px;"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="prev" rowspan="2"&gt;&lt;&lt;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td id="next" rowspan="2"&gt;&gt;&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="nm" style="height: 30px"&gt; &lt;td style="width: 15px;"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="section" colspan="5"&gt;Mix&lt;/td&gt; &lt;td style="width: 15px;"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="prev" rowspan="2"&gt;&lt;&lt;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td class="content"&gt;&amp;nbsp;&lt;/td&gt; &lt;td id="next" rowspan="2"&gt;&gt;&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;td class="title" &gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>as you can see, the table has 6 rows, and it is in a 3 - row repeating format. The contents are filled by a test.php fle which echos a <code>json encoded array</code> containing 5 members. In this way, all 5 cells having <code>class="title"</code> get populated successfully. But the second set with <code>class="title"</code> is not getting filled.. I made a <code>each(function(row)</code> to repeat the ajax call for every row having <code>class="nm"</code>. But this is not working.. I think the <code>[index]</code> is not getting reset after ajax, because the remaining cells are populating if I provide more than 5 members in array. But i want the ajax request to repeat after every row having <code>class="nm"</code> and want to fill the data acoordingly..</p> <p>How can I do this??</p> <p>Thanks in advance...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload