4 ms·
To be fair with the comparison, we should add error handling for the jQuery example: $.getJSON('/my/url') .done(data => { // success }) .fa
by divbzero 4y ago
To be fair with the comparison, we should add error handling for the jQuery example:
$.getJSON('/my/url')
.done(data => {
// success
})
.fail((jqxhr, textStatus) => {
if (textStatus === 'timeout') {
// connection error
} else {
// HTTP status error
}
})
And also consider the Fetch API alternative:
fetch('/my/url')
.then(response => {
if (!response.ok) {
// HTTP status error
}
return response.json()
})
.then(data => {
// success
})
.catch(error => {
// connection error
})