Without refresh fetch mysql database with ajax and php

Description

How to to used ajax in php how to fetch data for mysql database.How to 

fetch data without refresh page with ajax. How to used ajax in php and fatch

mysql database.How to retrieve and fetch data from mysql database in PHP using AJAX

Using JQuery. AJAX and php to fetch data from a database mysql database Step by 

Step

 

We can show the code ajax how to fetch mysql data with ajax

 

we can make function and used any place show in code 

 

function showComment(){

}

and showComment() 

 

Id set in div and fetch Database (#dismsgcomment)

 

showComment function used in bottom side code and fetch Data

 

eg : $("#result").html(data); 

showComment();

 

 

 

 

<script type = "text/javascript" >

// Jquery synatx

$(document).ready(function(){      <!------Start Ajax ---------->

  function showComment(){   <!------Make Function content---------->

     alert("check");

  //  var phonenocomment = $("#country_name").val();  

   var batchnamelist = $("#batchnamelist").val();   <!------by default take id you can used or not optional ---------->

                      $.ajax({

                        type:"post",

                        url:"batchactionfileajax.php",

data:"batchnamelist="+batchnamelist+"&action=showcomment", <!------send data to another file ---------->

 

                      // data:"action=showcomment",

                        success:function(data){

                             $("#dismsgcomment").html(data); // used just this ID dismsgcomment in Div show exapmle bottom side this page

                        }

                      });

                    }  

                    showComment();  // make function and used any place show exapmle bottom side this page

 

</script>

 

 

 

<script type = "text/javascript" >

// Jquery synatx

$(document).ready(function(){    <!------add content---------->

<!------show to content form---------->

  function showComment(){  

  //  var phonenocomment = $("#country_name").val();  

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

                      $.ajax({

                        type:"post",

                        url:"batchactionfileajax.php",

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

 

                      // data:"action=showcomment",

                        success:function(data){

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

                        }

                      });

                    }  

                    showComment();  // make function and used any place show exapmle bottom side this page

<!---------------->

<!------add content---------->

 

$("#subcomment").click(function() {  

 

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

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

// alert(batchnamelist); 

 

 if(desc != '')  

           { 

$.ajax({

url:'batchactionfileajax.php',

 

data:"batchnamelist="+batchnamelist+"&desc="+desc+"&action=addcomment", 

 

//data:{name:name,email:emailid,phoneno:phoneno,action:addcomment},

type:'POST',

success:function(data){

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

showComment();

 

}

 

});

 

 }  

           else  

           {  

                $('#result').html('');                 

           }       

 <!------ Condition apply on desction empty-------->

 document.getElementById("batchnamelist").value = "";

 document.getElementById("desc").value = "";

});

});

</script>