Both examples bellow return the same result:
Using success - error
$.ajax({
url: 'https://jsonplaceholder.typicode.com/users',
type: 'GET',
success: function(response) {
response.map(item => $('#data-list').append(`<li>${item.name}</li>`));
},
error: function(xhr) {
console.log(xhr.status);
console.log('There was an error');
}
});
Using done - fail
$.ajax({
url: 'https://jsonplaceholder.typicode.com/users',
type: 'GET'
})
.done(function(response) {
response.map(item => $('#data-list').append(`<li>${item.name}</li>`));
})
.fail(function(jqXHR, textStatus) {
console.log('Request failed: ' + textStatus);
});
What exactly is the difference? Does it have something to do with callback and promises?