jQuery AJAX
jQuery makes AJAX calls simple with its $.ajax() method and shorthands.
$.get() and $.post()
$.get("/api/users", function(data) {
console.log(data);
});
$.post("/api/users", {name: "Alice", age: 30}, function(response) {
console.log(response);
});$.ajax() — Full Control
$.ajax({
url: "/api/products",
method: "GET",
data: {category: "electronics"},
success: function(data) {
console.log(data);
},
error: function(xhr, status, error) {
console.error("Error:", error);
}
});$.getJSON()
$.getJSON("/api/data.json", function(json) {
$.each(json, function(i, item) {
$("ul").append("<li>" + item.name + "</li>");
});
});