"filter" json through ajax (jquery)
Posted
by Hyung Suh
on Stack Overflow
See other posts from Stack Overflow
or by Hyung Suh
Published on 2010-02-23T16:45:27Z
Indexed on
2010/05/10
0:38 UTC
Read the original article
Hit count: 341
I'm trying to filter the json array through ajax and not sure how to do so.
{ posts: [{"image":"images/bbtv.jpg", "group":"a"}, {"image":"images/grow.jpg", "group":"b"}, {"image":"images/tabs.jpg", "group":"a"}, {"image":"images/bia.jpg", "group":"b"}]}
i want it so that i can only show items in group A or group B.
how would i have to change my ajax to filter through the content?
$.ajax({
type: "GET",
url: "category/all.js",
dataType: "json",
cache: false,
contentType: "application/json",
success: function(data) {
$('#folio').html("<ul/>");
$.each(data.posts, function(i,post){
$('#folio ul').append('<li><div class="boxgrid captionfull"><img src="' + post.image + '" /></div></li>');
});
initBinding();
},
error: function(xhr, status, error) {
alert(xhr.status);
}
});
Also, how can I can I make each link process the filter?
<a href="category/all.js">Group A</a> <a href="category/all.js">Group B</a>
Sorry for all these questions, can't seem to find a solution.. Any help in the right direction would be appreciated.
Thanks!
© Stack Overflow or respective owner