Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ajaxPromise = function(params) {
- var deferred = Q.defer(); // Create the promise
- $.ajax(params) // Create the call normally
- .error(function(err) {
- deferred.reject(err); // Causes ths promise to fail
- })
- .success(function(result) {
- deferred.result(result); // You probably want to standardize your results here
- });
- return deferred.promise;
- };
- // You can then create shortcut methods for post, get, etc...
- ajaxPromise.post = function(params) {
- params.type = "POST";
- return ajaxPromise(params);
- };
- // etc...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement