Programming Tutorials

How to Make an HTTP Request in AJAX

By: Ram Baskar in Ajax Tutorials on 2022-08-01  

To make an HTTP request in AJAX, you can use the XMLHttpRequest object in JavaScript. Here's a basic example:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    // Handle the response here
};"GET", "", true);

This example makes a GET request to "" and logs the response to the console when the request is complete. You can modify the request method (GET, POST, etc.) and the URL as needed.

If you're using a library like jQuery, you can use the $.ajax() function to make HTTP requests:

  method: "GET",
  url: "",
  success: function(data) {
    // Handle the response here

This example is similar to the first one, but uses the $.ajax() function instead. You can modify the method, url, and success options as needed.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Ajax )

Latest Articles (in Ajax)