jQuery — Get and Post
$.get()
$.get("https://api.example.com/users", function(data, status) {
console.log("Status:", status);
console.log("Data:", data);
});
$.get with Data
$.get("https://api.example.com/users", { page: 2, limit: 10 }, function(data) {
console.log(data);
});
$.post()
$.post("https://api.example.com/users", {
name: "John",
email: "john@example.com"
}, function(data, status) {
console.log("Created:", data);
});
POST with JSON
$.ajax({
url: "https://api.example.com/users",
method: "POST",
contentType: "application/json",
data: JSON.stringify({ name: "John" }),
success: function(data) {
console.log(data);
}
});
With Promises
$.get("/api/data")
.done(function(data) { console.log("Success:", data); })
.fail(function(xhr, status, error) { console.log("Error:", error); })
.always(function() { console.log("Request complete"); });
Practical Example
// Submit form via AJAX
$("#myForm").submit(function(e) {
e.preventDefault();
$.post("/submit", $(this).serialize(), function(data) {
$("#result").text("Saved!");
});
});
Mini Practice
- Make a GET request to a public API
- POST form data
- Use promise methods done/fail
- Serialize a form for POST
Up Next
Continue with JSON — working with JSON data in AJAX.
Related Topics
Frequently Asked Questions about Get and Post
What is Get and Post in jQuery?
Get and Post is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Get and Post?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Get and Post.
Why is Get and Post important in jQuery?
Get and Post is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.