The $.ajax() method will send an AJAX request using jQuery. It takes several options that may be used to configure the request. Here's the most basic call for $.ajax():
$.ajax({
url: "https://example.com/api/data", // URL to send the request to
type: "GET", // HTTP method to be used-get, post, etc.
dataType: "json", // Format of response expected-html, json, text, etc.
data: { key1: "value1", key2: "value2" } // Data to send to the server goes here, optional
success: function(response) {
console.log("Response received:", response); // Code to run if the request is successful
},
error: function(xhr, status, error) {
console.log("Error occurred:", error); // Code to run if the request fails
}
});