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.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Ajax )
A complete sample program in AJAX
How to Make an HTTP Request in AJAX
Latest Articles (in Ajax)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate