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

  • SEARCH
  • Home
  • 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 8828111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:31:56+00:00 2026-06-14T07:31:56+00:00

I am trying to fetch book rows by books’ first letter with jquery $.post

  • 0

I am trying to fetch book rows by books’ first letter with jquery $.post into my <td> </td> which is part of my table.

My table looks like :

<table id="myTable">

  <thead>
    <tr>
      <th class="page">pages</th>
      <th class="book_name">Book Name</th>
      <th class="author">Author</th>
    </tr>
  </thead>

  <tbody id="result_list">
  <!--Here is data which will come with ajax($.post) -->                 
  </tbody>
</table>

Writing jquery code, I become successful but with $("#result_list").html(data) like this:

$.post( "/ajax.php", { book_first_letter: 'A'},
  function( data ) {
      $( "#result_list" ).html( data );
  }
);

But I dont want to fetch all data as HTML and insert into <tbody> . I want to fetch data from ajax.php as separate variable. For example; book_name,logo,pages,author. And I want to insert them into <td> </td>.

My ajax.php is like this:

 $letter= trim($_POST['book_first_letter']);    
 $query = $this->book_model->get_books_by_letter($letter);       
 foreach ($query as $book) { ?>

     <tr>
         <td> <?php echo $book->page; ?> </td>
         <td> <?php echo $book->name; ?> </td>
         <td> <?php echo $book->author; ?> </td>

     </tr>
   <?php  
}
?>

Is there any way to take each variable(i.e. $book->name) and insert it into <td></td> ?

  • 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-06-14T07:31:57+00:00Added an answer on June 14, 2026 at 7:31 am

    Not only can you, but you should.
    Rather than having PHP return html as text, have it return a JSON object.

    You’re going to need to do a few things.
    First add a fourth argument to your $.post() call for a dataType of “json”.

    $.post( "/ajax.php", { book_first_letter: 'A'}, callback, "json" );
    

    Then, its good form to have PHP send JSON headers for the result so before you send out any data in PHP use

    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    

    And rather than echoing out the properties of your book model, just use json_encode()

    $letter= trim($_POST['book_first_letter']);    
    $books = $this->book_model->get_books_by_letter($letter);
    echo json_encode( $books );
    

    So the client now has the raw data and you can use js/jQuery to loop through the books and add it to your table.

    function callback( books)
    {
       var i = 0, len = books.length, html = "";
    
        for( ; i < len; ; )
        {
            html += "however you want to structure the data";
        }
    
        $( "#result_list" ).html( html );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fetch wcf service from jquery. I have written below code
Trying to fetch the router address in an app. I found this post Objective-C
I'm trying to call book details from the relationships table in my database, mysql
When I am trying to fetch the record from a table in SQLServer2008 am
I am trying to fetch the information from books associated with a customer but
I am trying fetch the picture which is captured by the camera in the
I am trying to fetch the html source from this usl: http://books.google.com/books?id=NZlV0M5Ije4C&dq=isbn:0470284889 I used
I'm trying to fetch associations of a model dynamically. For ex; model1 has_many model2s
I'm trying to fetch data from a page that resides on an intranet. The
I am trying to fetch a gzip from a URL and import it automatically

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.