Created
September 8, 2016 15:43
-
-
Save mlent/d23cbd5b3f5935229933acd82263321a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sendDataToAmazon(dataToSend) { | |
return getAmazonKey() | |
.then(getUrlWithKey) | |
.then(function(url) { | |
/* Sometimes it's easier to inline if you have | |
data passed into original function which is only | |
needed in the middle of a promise chain*/ | |
return sendDataToUrl(url, dataToSend); | |
}) | |
.then(updateUI); | |
} | |
function getAmazonKey() { | |
return $.get('/amazon/keys').then(function(data) { | |
return { key: data.key, ; | |
} | |
} | |
function getUrlWithKey(key) { | |
return $.get('/amazon/urls?key=' + key).then(function(data) { | |
return data.url; | |
}); | |
} | |
} | |
function sendDataToUrl(url, dataToSend) { | |
return $.ajax({ | |
method: 'POST', | |
url: url, | |
data: dataToSend, | |
encoding: 'whatever-files-types?' | |
}); | |
} | |
function updateUI(data) { | |
$('#my-selector').html('It worked!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment