Last active
February 12, 2017 05:53
-
-
Save maximgatilin/b096f40f9b4c4007f7e7eb559549af6c to your computer and use it in GitHub Desktop.
jquery promises #tags:promises
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
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