Already looked through a lot of information on this topic, but I just can’t solve my little problem.
Purpose: obtain data k => v
Returns an array type object from php
if(isset($_POST['getComment'])) { echo json_encode(array( array( "name" => "Viktor", 'comment' => "коментарий Виктора"), array( "name" => "Петя", "comment" => "коментарий Пети") )); } I'm trying to sort it out in js.
function createFunc(data) { data = JSON.parse(data); // $('body').append("<div id='com'></div>"); for (var i in data) { for (var j in data[i]) { $('#com').append($("<p> " + i +" : " + j + " : "+ data[i][j] + "</p>")); } } } It is necessary to refer to the key of one array - get the values separately - the name is
Next is the value of comment . And so with each array in the hierarchy. and get all the values at once. all values in all arrays.
I understand perfectly well that the statement of the question, like the question itself, is a trifling one. But I can't figure it out. Thanks in advance to everyone who took the time to this problem.