I'm using Zepto
in my application as an alternate to jQuery
and I was working on a task when I realized, $.ajax
have a error handler, but other methods like $.post
, $.get
does not have it.
What can be the reason for this?
$.post(url, [data], function(data, status, xhr){ ... }, [dataType])
$.get(url, [data], [function(data, status, xhr){ ... }], [dataType])
According to your question about $.get
and $.post
. Yes, source code on github answered that there is no error handlers for this methods, but you can add common error handler in $.ajaxSettings
But instead of $.ajax
with callbacks better use Zepto deferred API. You must include it manually.
It provides $.Deferred
promises API. Depends on the "callbacks" module.
When included, $.ajax()
supports a promise interface for chaining callbacks.
With deferred you can catch error in deferred/promise chains:
$.post(/*any options*/).done(/*success handler*/).fail(/*error handler*/)
or
$.post().then(function() {
// success code here
}, function() {
// error code here
});