jQuery Ajax post Method


jQuery Ajax post method loads data from server using the HTTP POST Request.


jQuery Ajax $.post() Method Syntax

$.post(url,function(response,status));

url(Required): Url of the file you want to load.
function : (optional): Callback is executed when the request completes.

jQuery Ajax post method Example

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#ajaxExample" ).on( "click", function(event) {             
                          var uri = 'http://runtest.tutorialsplane.com/php/';
                          var firstName = $("#fname").val();
                          var lastName = $("#lname").val();
                          $.post(uri+"post_method_demo.php",{firstName,lastName},function(response,status){
                              alert("Status = "+status+" Response = "+response);
                          });     
              });               
          });
</script>

Try it »

Output :

jQuery Ajax post Method

jQuery Ajax post Example


note : post_method_demo.php contains the following code

Post Method Demo

You Posted :

<?php
if(isset($_POST['firstName'])){
echo "first name = ".$_POST['firstName']."";
}
if(isset($_POST['lastName'])){
echo "  last name = ".$_POST['lastName']."";
}
?>




Advertisements

Add Comment