$.get() and $.post() MethodsjQuery provides simplified AJAX helper methods such as $.get() and $.post() to communicate with servers using HTTP GET and POST requests.
.fail().
// jQuery AJAX helper method syntax
$.get(url, [data], [callback], [dataType]);
$.post(url, [data], [callback], [dataType]);
// Fetch data from server using GET
$('#getBtn').click(function() {
$.get('https://jsonplaceholder.typicode.com/posts/1', function(data) {
$('#getResult').text(JSON.stringify(data, null, 2));
}).fail(function() {
$('#getResult').text('Error retrieving data.');
});
});
// Send data to server using POST
$('#postBtn').click(function() {
$.post('https://jsonplaceholder.typicode.com/posts',
{ title: 'foo', body: 'bar', userId: 1 },
function(data) {
$('#postResult').text('Response:\n' + JSON.stringify(data, null, 2));
})
.fail(function() {
$('#postResult').text('Error sending data.');
});
});
Try sending your own custom data to the server using $.post():
The GET request retrieves a JSON object from the server, while the POST request sends data and receives a response object created on the server.
.fail()./users/1..done() and .always().