How to use AJAX using PHP and jQuery

ByShubham Jain

How to use AJAX using PHP and jQuery

Ajax

  • Ajax is an Asynchronous JavaScript and XML.
  • with the help of ajax is build the connection between the server and client.
  • This technology is used for quick and dynamic web pages.
  • Ajax is work without reloading the page.
  • Examples of applications using AJAX: Google Maps, Gmail, and Facebook tabs.

Step to ajax example:-

  • First, we download jquery jar file.
  • Create a client-side
  • Create a server-side page to process the request.

Ajax Example:-

To create ajax example, you need to use any server-side language e.g. Java, PHP etc. Here we are using PHP for generating the server-side code.

And client-side language is HTML, CSS and We are using ajax with jquery.

Example:-

  • First, we create an input

  <!DOCTYPE  html>

 <html lang=”en”>

<head> 
       <script> 
      function beforesubmit()
$.ajax({ 
     url: “table.php”,                                           // write url  here
type: “GET”,                                                  // url type is here like .(GET&POST)
data: “table= “+$(“#table”).val(),            // data type is here
success: function (response) {
 $(“#bb”). append(response);                    // output of ajax
                                                                          }
  });
 return false;                                                 // if error not submit the page
}
</script> 
 </head>
 <body>

<h1> Enter the number of which you want a table </h1>
 <form action=”” method=”Get”  id=”form”>
<input type=”text” placeholder=”number” id=”table” required=””>

<input type=”submit” value=”Submit” onclick=” return beforesubmit()”>
</form>
<div id=”bb”> </div>
<script src=”jquery.js”> </script>

</body></html>

 

  • on click=” beforesubmit()” executes the JavaScript function show Name every time a click is typed in the text box.
  • Create table.php page for server-side

 

 <?php $i = 1;
 $number = $_GET[‘table’];  // $number is a input value 
 for ($i ;$i<=10; $i++) {
 echo ($i*$number).” <br>”;  //print 10 times table value 
 }
 ?>

     Output

Final Page is 

About the author

Shubham Jain administrator

    Leave a Reply