2

I want to get the json content, status and other response attributes in a single callback.I cannot go much further than example code:

fetch('/users.json') .then(function(response) { console.log(response.status) return response.json() }).then(function(json) { console.log('parsed json', json) }) 

I can print the status, but trying to return both response status and json in the first callback leads to the second callback getting a Promise, which I think is square one!

How do I get json as well as other attributes in a single callback?

1 Answer 1

1

Try this:

.fetch('/users.json') .then(function(response) { return { status: response.status, data: response.json() }; }).then(function(result) { console.log('parsed json', result.data); console.log('status', result.status); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

Still getting a Promise object

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.