$.post() Method in jQuery


$.post() method used send data to the server with an HTTP POST request.

Example:

The following example show, how to send data to sample.php using jQuery post() method.

 
<html>
  <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
  <body>
    <div id='res'></div>
  </body>
  <script>
    $(document).ready(function(){
      $.post("sample.php",{name:"Tom"},function(data){
        $("#res").html(data);
      });
    });
  </script>
</html>
sample.php
<?php 
  echo "Hi ".$_POST["name"].".This is Sample Text from external PHP File";
?>

Output :

Hi Tom.This is Sample Text from external PHP File