Jump to content

Send div Results via Ajax


johnnys

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/292344-send-div-results-via-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.