Some people have faced problem in use of jquery ajax with PHP that how to post and how to display response data from PHP.
Here i am using different kind of examples for jquery ajax using PHP.
Example:
index.php : Write below code in any editor and save as index.php file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(document).ready(function() { $(".submitButton").click(function(){ var dataString = jQuery("form").serialize(); $.ajax({ type: "POST", url: "ajax.php", data: dataString, success: function(html){ $("#loadplace").html(html); } }); return false; }); }); </script> </head> <body> <div id="loadplace" > </div> <br/> <form action="" method="post"> <table cellpadding="0" cellspacing="0" width="500px"> <tr><td>Name </td><td><input type="text" name="name"/></td></tr> <tr><td>Address </td><td><input type="text" name="address"/></td></tr> </table> <input type="submit" value="Submit" class="submitButton" /> </form> </body> </html>
ajax.php : Write below code in any editor and save as ajax.php file.
<?php $name = $_POST['name']; $address = $_POST['address']; ?>
<b>Name :</b> <?php echo $name; ?> <b>Address :</b> <?php echo $address; ?>