Press enter to see results or esc to cancel.


jQuery Ajax GET and POST Requests Examples


In this video I have shown step by step how you can create a GET and POST request forms with PHP front end page.
So the php pages and the js file needed are below shown,

You can download the js file herejquery.min.js.rar

index.php with form to send GET Request to page the page get.php with the parameters name1 and address1.
index.php

<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
 $("button").click(function(){
 var name=$("#name").val();
 var address=$("#address").val();
 alert(name);
 alert(address);
 $.get( "get.php",
 {
 name1:name,
 address1:address
 }
 ,function( data ) {
 alert(data );
 });
 });
});
</script>
</head>
<body>
<center>
<h1>Jquery Get Request Test</h1>
<form>
Name : <input type="text" id="name"/><br>
Address : <input type="text" id="address"/><br>
<button>Submit</button>
</for>
</center>
</body>
</html>

index.php after running on server


get.php to receive and print the parameters from the index.php page.
get.php

<?php 
$name=$_GET['name1'];
$address=$_GET['address1'];
echo 'Your name is '.$name;
echo 'Your address is '.$address;
?>

On submitting the form, Get.php loads with the data submitted.


index_POST.php with form to send GET Request to page the page get.php with the parameters name1 and address1.
index_POST.php

<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
 $("button").click(function(){
 var name=$("#name").val();
 var address=$("#address").val();
 alert(name);
 alert(address);
 $.post( "post.php",
 {
 name1:name,
 address1:address,
 }
 ,function( data ) {
 alert(data );
 });
 });
});
</script>
</head>
<body>
<center>
<h1>Jquery Post Request Test</h1>
<form>
Name : <input type="text" id="name"/><br>
Address : <input type="text" id="address"/><br>
<button>Submit</button>
</for>
</center>
</body>
</html>

index_POST.php after running on server


post.php to receive and print the parameters from the index.php page.
post.php

<?php 
echo 'Sucess post call test';
echo 'Your name is '.$_POST['name1'];
echo 'Your address is '.$_POST['address1'];
?>

On submitting the form, post.php loads with the data submitted.

 

Download complete project here,

jquery_get_post_source_code