Answer the question
In order to leave comments, you need to log in
How to output required data from json string to div when requesting php?
Making a request from a form:
<form action="input1_save.php" method="post">
<input type="text" name="num" value="2">
<input type="text" name="id" value="32">
<input type="submit" name="" value="go">
</form>
<div id="out">
<div id="name"></div>
<div id="f_name"></div>
<div id="enable"></div>
</div>
[
{
"conf":{
"type":"text",
"tech_type":"js",
"parser":"jq",
"comm1":"5mr",
"comm2":"priv",
"name":"Petr",
"f_name":"Ivanov",
"enable":"no"
}
}
]
Answer the question
In order to leave comments, you need to log in
HTML
<div class="out"></div>
<!-- пустой div для вывода данных-->
// в скобках JSON.parse() ответ сервера json
const answer = JSON.parse('[{"conf":{"type":"text","tech_type":"js","parser":"jq","comm1":"5mr","comm2":"priv","name":"Petr","f_name":"Ivanov","enable":"no"}}]')[0].conf;
const out = document.querySelector('.out'); // находим div
out.innerHTML =''; // очищаем его
for (key in answer) { //перебираем объект
out.innerHTML += '<div id="'+key+'">'+answer[key]+'</div>'; добавляем внутрь out
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question