jQuery
AJAX Requests
Use $.ajax, $.get, $.post, and load with promises.
By EZ4Code Team
ajaxhttp
Code
// Promise-based $.ajax
$.ajax({
url: "/api/users",
method: "GET",
dataType: "json"
})
.done(data => console.log("users", data))
.fail((xhr, status) => console.error("error", status));
// Shorthands
$.get("/api/posts", posts => render(posts));
$.post("/api/posts", { title: "Hi" }, post => console.log(post));
// JSON-P and loading HTML into an element
$("#result").load("/fragment.html #content");Explanation
jQuery's $.ajax returns a jqXHR promise supporting done/fail/always callbacks. Shorthand helpers $.get and $.post cover common GET/POST cases, while load() fetches HTML and injects it into the matched element. Set dataType to auto-parse JSON responses.
More jQuery Snippets
Selectors
Select elements by id, class, attribute, and pseudo-filters.
Events & Delegation
Bind handlers with on(), support delegation and namespaced removal.
DOM Manipulation
Get/set text, html, attributes, classes, and insert nodes.
Effects & Animation
Show, hide, fade, slide, and animate elements.
Traversing the DOM
Navigate relatives and filter the matched set.
Utility Methods
Iterate, merge, and filter with jQuery helpers.