Jump to content

Send div Results via Ajax


johnnys
Go to solution Solved by Barand,

Recommended Posts

I am creating a library app (personal dev) and have ran into some trouble. I'm very new to Ajax and Php

 

I have a page named addEntryISBN which shows the results of a user search in a div named #results. I want to post the contents of #results to my database. The contents of #results comes from a page named searchISBN.

 

What is the most effective way of doing this? My code so far is aas follows;

 

addEntryISBN.php

$(document).ready(function() {
        $('form').on('submit', function (e) {
          e.preventDefault();
          $.ajax({
            type: 'post',
            url: 'searchIsbn.php',
            data: $('form').serialize(),
            success: function (result) { 
            $('.result').html(result);
            }    
          });
return true;
        });
});

<div class="result"</div>
 

searchISBN.php

 

<?php       
echo '<table class="table">';


                                echo '<tr>';
                                echo '<h3>Book Info</h3>';
                                echo '</tr>';
                                
                                echo '<tr>';
                                echo '<td> Title </td>';
                                echo '<td>' . $title . '</td>';
                                echo '</tr>';
    
                                echo '<tr>';
                                echo '<td> Page Count </td>';
                                echo '<td>' . $pageCount . '</td>';
                                echo '</tr>';
                                
                                echo '<tr>';
                                echo '<td> Publish Date </td>';
                                echo '<td>' . $publishDate . '</td>';
                                echo '</tr>';
                                
                                echo '<tr>';
                                echo '<td> Description </td>';
                                echo '<td>' . $description . '</td>';
                                echo '</tr>';
                                
echo '</table>';   
echo '<form><input id="add_isbn" method="post" type="submit" value="Add This Book" /></form>';
}  
?>

I hope this makes sense!

 

Any help is much appreciated.

 

J

 

 

 

Edited by johnnys
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.