Last active
December 11, 2015 23:08
-
-
Save zhannes/4674505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assumes Q.js has been loaded and available as Q | |
function ajaxCall(){ | |
var dfd = Q.defer(), | |
data = getData({ | |
success: function(response){ | |
dfd.resolve(response); | |
}, | |
error: function(error){ | |
dfd.reject(error); | |
} | |
}); | |
return dfd.promise; | |
} | |
var loadData = ajaxCall(); | |
/* loadData returns a promise, and promises respond to .then() */ | |
loadData | |
.then(function(data){ | |
// do stuff with the data | |
}) | |
.fail(fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment