Printing out JSON array returned [closed]
Question
I have the following JSON array:
[{"occurences":"1","post_title":"Test 1","ID":"16"},
{"occurences":"1","post_title":"Test 2","ID":"19"},
{"occurences":"1","post_title":"\u543b\u60a8\u7684\u5c41\u80a1","ID":"21"}]
And I use this js to parse and print it:
success:function(data){
$.each(data, function(i, post){
content = '';
content += '<li>' + post.post_title + '</li>';
});
$(content).appendTo("#search-results");
}
But the display only showed "Undefined", and the Console showed no errors.
In case you ask, this is the HTML part:
<form id="search" action="">
<div class="toolbar">
<h1>Search</h1>
<a href="#" class="back">Back</a>
</div>
<ul class="rounded">
<li><input type="text" name="search-text" placeholder="Search" id="search-text" /></li>
</ul>
<ul class="edgetoedge" id="search-results">
<li class="sep">Results</li>
</ul>
</form>
Any clue why? Many thanks in advance!
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange