using $.get promise (jquery 3.3.1) won't display any error, which makes debugging impossible
$.get('/').then(function() {
console.log(undef)
})
fetch('/').then(function() {
console.log(undef)
})
The first example is silent, no error thrown
The second example throws as expected "Uncaught (in promise) ReferenceError: undef is not defined"
Is it a jquery bug or am I using it in a wrong way? How'd you suggest using fetch instead? I'm concerned about browser comatibility
You can add the fail function in the chain:
$.get('/').then(function() {
console.log(undef);
})
.fail(function(){
console.log("Error");
})
Reference
This is by design. then() only executes when a request completes successfully.
If you want to know when a request has failed add a fail() handler:
$.get('/').then(function() {
console.log(undef);
}).fail(function() {
// something went wrong...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With