Answer the question
In order to leave comments, you need to log in
How to extract data from JSON and insert it into a div?
Hello, I learned how to send and receive data from the API in JSON format, but I can’t figure out how to display data from JSON, for example, in a div.
Such introductory:
There is a response in JSON format from the API
"status":"success",
"data":{
"name":"Антон",
"alternative_name":"Gooblyyn",
"year":29
}
<div id="Name">Nick: </div>
<div id="Year">Год: </div>
Answer the question
In order to leave comments, you need to log in
fetch("http://api.com/api/query?id=1").
then(ret=>ret.json()).then(ret=>{
$("#Name").text("Nick: "+ret.data.name);
$("#Year").text("Years old: "+ret.data.year)
})
Judging by the previous questions, you need to start learning front-end development.
There are many libraries and frameworks for this. The jQuery option is good, but it's outdated.
It is necessary to dive into the world of the front-end, and then such questions will immediately be clear.
You can take React or Vue , there is a lot of documentation on them and a quite acceptable entry threshold.
PS: for API requests I would use " axios ". It is easy to use in much the same way as a normal "fetch".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question