A typical example of the fetch, which is full of Google (specifically this one with the habr):
fetch('http://some-site.com/cors-enabled/some.json', {mode: 'cors'}) .then(function(response) { return response.text(); }) .then(function(text) { console.log('Request successful', text); }) .catch(function(error) { log('Request failed', error) });
But how to get access to the response
from the second then
?
I, of course, can just push it into some external variable before return response.text()
, but in general it looks somehow unreliable, because asynchronous, stupid user clicks the button twice, for example, some other response
another request will be fantastic luck.
I would like to just transfer it further to the function, and, I suspect, we must somehow foster our promises, but I'm still not cool enough to pile them up on my own, I'm afraid to mess things up.
response.text()
is a promise and I also need to somehow get the result - andreymal