0

I am trying to fetch data from JSON and then append it to the HTML body.

Unfortunately, I manage to only fetch the object like so:

fetch( 'https://www.url.com/getdata/showid?userId=433642', {
    method: 'get'
}).then( function( response ) {
      return response.json();
}).catch( function( err ) {
    // Error
});

The JSON data looks like so: {"id":"542434","formattedId":"66-44-3224-23"}

What is the best way to append the JSON response to the page body?

user3132858
  • 609
  • 1
  • 11
  • 27
  • 1
    Re 'returning the data from the request', simple answer: don't. This is not how the asynchronous pattern works. See the duplicate I marked for more information. To append content to the body, use `append()`. – Rory McCrossan May 08 '18 at 08:54
  • Hi, I am doing this for testing purposes. For some reason I cannot make the `append()` function work as it should and append the object promise to the page body, any idea why this could be? – user3132858 May 08 '18 at 09:24

0 Answers0