Syntax of ajax in php with mysql database with example

Description

Basic syntax of ajax used in php with mysql database with example Step by Step   How to access and used JQuery AJAX and php to fetch and display data from a mysql database .Working with ajax php and mysql without refreshing fetch data from mysql database.

<script>  

 $(document).ready(function(){  // document ready Start

      $('#batchselect').click(function(){

// Select dropdown ID name Action on click

   var batchselect = $("#batchselect").val(); 

                      $.ajax({ 

                        type:"post", 

                        url:"courinaddactionlist.php", 

                       data:"batchselect="+batchselect+"&action=showcomment",

                      // data:"action=showcomment", //

                     // data:"phonenocomment="+phonenoset+"",

                        success:function(data){

                             $("#dismsgcomment").html(data); 

  // ID Name set Same in PHP Div

                        }

                      });

      });  

 });  

 </script>

 

PHP Onclick search Ajax Data

<select class="form-control" id="batchselect" name="batchcodeselect" style="width:628px;" >

 <option value=""> Select Course </option>

<?php

$showst=mysql_query("Select * from coursetimetable");

   while($rowlinkst=mysql_fetch_array($showst)){?> 

<option value="<?php echo $rowlinkst['id']; ?>,<?php echo $rowlinkst['coursename']; ?>"><?php echo $rowlinkst['coursename']; ?></option>

<?php } ?>

</select>

 

PHP syntax :

 <div class="col-lg-12" id="dismsgcomment" style="color:#000000;  padding: 14px 0px;"></div>