I have a fetch statement that relies on the value of another fetch statement. When I execute the below, the first fetch succeeds (returns the user), but the second fetch that relies on the value from the first fails with TypeError: Failed to fetch. I've tried this against MS Edge, FF and Chrome with the same result (I've also tried asnyc/await, and that resulted in the same issue). I've tested each of these calls independently (the second with john-doe hard-coded into the call). They work independently (the service on the back-end is Jersey).
I am coming from a jQuery background, where I would do the below using $.when, but we are trying to get away from libraries and frameworks in our office. Any help would be greatly appreciated. I've tried every solution I've found on this site and elsewhere with no success.
fetch('/my_services/rest/services/getUser')
.then(function(response) {
return response.text();
})
.then(function(data) {
alert(data); // correctly displays "john-doe"
return fetch('/my_services/rest/services/getMetaForUser/' + data);
})
.then(function(response) {
return response.text();
})
.then(function(data) {
alert(data);
})
.catch(function(error) {
alert(error); // TypeError: Failed to fetch
});