$.ajax("example.php").done(function ()
{
alert(...);
}).fail(function ()
{
alert(...);
}).always(function ()
{
alert(...);
});
vs
$.ajax("example.php",
success: function ()
{
alert('');
},
error: function ()
{
alert('');
},
complete: function ()
{
alert('');
}
);
Sorry , I can’t see any advantages
Can you please explain ?
Or maybe can you give me example of the former which cant be accomplished by the latter…?
For starters, the second code block isn’t even syntactically valid. I’d call that an advantage of the first
:PBut in all seriousness:
It’s just a different syntax for achieving the same end result. One immediate advantage is that you can wire up multiple functions for each outcome with deferred:
otherwise you’d have to do it like so:
Other advantages, quoted from How can jQuery deferred be used?