extract items from json encoded array with jquery
2 posts
Page 1 of 1
Hello im trying to echo an array into div boxes however i cant get it working probaly, so heres my question. how can i do so that this code will create a div box and populate it with my array
heres my code i have so far,
heres my code i have so far,
Code: Select all
and this is my array, its inside another array so double array, and is json encoded
$.each( data, function( key, value ) {
$.each( value, function( key2, value2 ) {
$('<h1/ id="test">').text(value2).appendTo('#search_results');
});
});
Code: Select all
i would like it to look like this
[{"id":"4","title":"test1"},{"id":"5","title":"test2"},{"id":"6","title":"test3"},{"id":"7","title":"test4"},{"id":"9","title":"test6"}]
Code: Select all
<div class="myclass">
<h2>The title</h2>
<h2>The id</h2>
</div>
<div class="myclass">
<h2>The title</h2>
<h2>The id</h2>
</div>
This has been resolved with this code
Code: Select all
$.each(data, function() {
$('#search_results').append('<div class="result"><a href="item.php?id=' + this.id + '">' + this.title + '</a>');
});
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023