deferred.catch()

Add handlers to be called when the Deferred object is rejected.

.deferred.catch(failFilter)👒 Promise

failFilter Function A function that is called when the Deferred is rejected.

deferred.catch( fn ) is an alias to deferred.then( null, fn ). Read its page for more information.

Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can add rejection handlers using the .catch method.

HTML
$.get("test.php")
 .then(function () {
 alert("$.get succeeded");
 })
 .catch(function () {
 alert("$.get failed!");
 });
DEMO

Looking for a Web Developer?

πŸ‘‹

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /