extract items from json encoded array with jquery

2 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

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,
Code: Select all
$.each( data, function( key, value ) {
	$.each( value, function( key2, value2 ) {
		$('<h1/ id="test">').text(value2).appendTo('#search_results');
	});
});
and this is my array, its inside another array so double array, and is json encoded
Code: Select all
[{"id":"4","title":"test1"},{"id":"5","title":"test2"},{"id":"6","title":"test3"},{"id":"7","title":"test4"},{"id":"9","title":"test6"}]
i would like it to look like this
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>
https://t.me/pump_upp
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

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>');
});

https://t.me/pump_upp
2 posts Page 1 of 1
Return to “Help & Support”