Wednesday, July 2, 2014

Wait for it....

Deferred Objects with jquery.  Great for when you are waiting for data to process or servers to reply.

var deferredData = $.Deferred();
deferredData.done(function(result)
{
     //do stuff
}).fail(function(errorObj)
{
     //handel error
}).always(function(result)
{
     //whatever is returned comes here as well.
});

// when the data is done simply call
deferredData.resolve(result);

//or if you want to fail
deferredData.reject(errorObj);

No comments:

Post a Comment