Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6065215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:21:56+00:00 2026-05-23T09:21:56+00:00

I am using jQuery and I have script as below; $(document).ready( function() { $(‘.nm’).each(function(row)

  • 0

I am using jQuery and I have script as below;

$(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(" ");
          }
      });
  },
});
});
});

The script is suppose to change text in my table;

<tr class="nm" style="height: 30px">
        <td style="width: 15px;">&nbsp;</td>
        <td class="section" colspan="5">Mix</td>
        <td style="width: 15px;">&nbsp;</td>
    </tr>
    <tr>
        <td id="prev" rowspan="2"><<</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td id="next" rowspan="2">>></td>
    </tr>
    <tr>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
    </tr>


    <tr class="nm" style="height: 30px">
        <td style="width: 15px;">&nbsp;</td>
        <td class="section" colspan="5">Mix</td>
        <td style="width: 15px;">&nbsp;</td>
    </tr>
    <tr>
        <td id="prev" rowspan="2"><<</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td class="content">&nbsp;</td>
        <td id="next" rowspan="2">>></td>
    </tr>
    <tr>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
        <td class="title" >&nbsp;</td>
    </tr>

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 file which echos a JSON encoded array containing 5 members. In this way, all 5 cells having class="title" get populated successfully. But the second set with class="title" is not getting filled.

I made a each(function(row) to repeat the ajax call for every row having class="nm". But this is not working. I think the [index] 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 class="nm" and want to fill the data accordingly.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:21:57+00:00Added an answer on May 23, 2026 at 9:21 am

    $('.title') always selects every .title element. You are not restricting the set to any particular one. You have to make the selector dependent on .nm somehow.

    For example:

    $('.nm').each(function() {
       var $row = $(this);
        $.ajax({
            type: 'POST',
            url: 'test.php',
            data: 'id=' + 1,
            dataType: 'json',
            cache: false,
            success: function(result) {
                var $titles = $row.next().next().children('.title');
                if (result) { // it's enough to check *once* whether it is set
                    $titles.html(function(index){ // easier
                        return result[index];
                    });
                }
                else {
                   $titles.html("&nbsp;");
                }
            });
        });
    });
    

    This should work with the structure you provided. $row references each <tr class="nm"> row and $row.next().next() will select second next sibling, which is the row that contains the .title elements.
    It will break if you change the structure.

    It would be better if you give the rows containing the .title elements their own class:

    <tr class="something">
        <td class="title" >&nbsp;</td>
        <!-- ... -->
    </tr>
    

    Then you can iterate of those instead of the .nm rows, and get the .title elements with $row.children('.title').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this jQuery-AJAX code below and a form: <script type=text/javascript> $(document).ready(function () {
I have created a function outside of $(document).ready() , but am still using jQuery
I have an ajax script executed using jquery when an input text field is
I have a form I am submitting using jQuery's ajaxSubmit function from the Forms
Is it possible that using jQuery, I cancel/abort an Ajax request that I have
I have written some code using jQuery to use Ajax to get data from
For example, I'm using the script below to check for empty fields : $('a.submit').click(function()
Alrighty so below I have this script doing exactly what I want; I'm using
I have recently encountered a problem in IE, using the jQuery UI datepicker script:
I am using jQuery's Datepicker for a textbox as below. I have restricted the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.