Category: javascript
ajax with jquery
Published on 30 Sep 2026
Explanation
AJAX allows a web page to communicate with the server without performing a full page reload.
Code:
Browser | | AJAX Request v Server | | JSON Response v Browser
Explanation
The $.ajax() method provides detailed control over HTTP requests.
Code:
$.ajax({
url: '/api/users',
method: 'GET',
success: function(data) {
console.log(data);
}
});
Explanation
The $.get() method provides a shorter way to send a GET request.
Code:
$.get('/api/users', function(data) {
console.log(data);
});
Explanation
The $.post() method sends data to a server using an HTTP POST request.
Code:
$.post('/api/users', {
name: 'Praveen',
email: 'p@example.com'
}, function(response) {
console.log(response);
});
Explanation
AJAX can send JSON data to a REST API by specifying the content type and converting the object to JSON.
Code:
$.ajax({
url: '/api/users',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({
name: 'Praveen'
}),
success: function(response) {
console.log(response);
}
});