In this article, you will learn How to Create AJAX get() and post() Method. jQuery AJAX gets and post method is an important role in the HTTP server request.

jQuery Get() Method

<html>
<head>
<title>jQuery get() Method</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.get("get.php", function(data, status){
      alert("Data: " + data + "\nStatus: " + status);
    });
  });
});
</script>
</head>
<body>
<button>Send HTTP GET request to page</button>
</body>
</html>

jQuery post() Method

<html>
<head>
<title>Jquery AJAX post() Meithod</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.post("post.php",
    {
      name: "Nisha Sharma",
      city: "Amritsar"
    },
    function(data,status){
      alert("Data: " + data + "\nStatus: " + status);
    });
  });
});
</script>
</head>
<body>
<button>Send HTTP POST request to a page</button>
</body>
</html>

Read on Facebook