S
S
sabirovvlad02018-08-17 09:07:10
JavaScript
sabirovvlad0, 2018-08-17 09:07:10

How to display data through the API on the page?

How to display html page data by json

if (isset($_POST['submit'])) {
  $result = $_POST["input"];
}

else {
  echo "ERROR";
}

fetch('https://jsonplaceholder.typicode.com/<?php echo "$result" ?>')
 		.then(response => response.json())
 		.then(json => console.log(json));

I output this to the console, but when I output it through document.writeit, it displays {object Object}
and I want to display the
id
body
with the data that is inside

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-08-17
@zolt85

Use JSON.stringify()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question