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
 console.log(this.responseText);
 }
};
xhttp.open("GET", "https://example.com/api", true);
xhttp.send();

This example makes a GET request to "https://example.com/api" 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:

$.ajax({
 method: "GET",
 url: "https://example.com/api",
 success: function(data) {
 // Handle the response here
 console.log(data);
 }
});

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

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /