Skip to content

Instantly share code, notes, and snippets.

@maximgatilin
Last active February 12, 2017 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximgatilin/b096f40f9b4c4007f7e7eb559549af6c to your computer and use it in GitHub Desktop.
Save maximgatilin/b096f40f9b4c4007f7e7eb559549af6c to your computer and use it in GitHub Desktop.
jquery promises #tags:promises
function getUserLocation() {
return $.ajax('https://www.example.com/location.json'); // note the `return`
}
function getCurrentWeather(userLocation) {
return $.ajax('https://www.example.com/weather' + userLocation + '.json');
}
getUserLocation().then(getCurrentWeather).then(function(data) {
// location data here
});
// todo in error cases paste error methods into then method as second parametr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment