I downloaded and edited a code that from internet, basically what I want to do is to create a list of strings that I’m reading from the database using JSON.
The list is built perfect, now what I want to do is to filter results (text box) using Jquery.
What’s the best way to do that?
Show the full list of results when users type something in a textbox filter those results in the list.
Thanks
$(function ()
{
$.ajax({
url: 'api.php', data: "", dataType: 'json', success: function(rows)
{
var list = $("#toggle").append('<ul></ul>').find('ul');
for (var i in rows)
{
var row = rows[i];
//var id = row[0];
var Dname = row[4];
Dname = Dname.toLowerCase();
list.append("<li>"+Dname+"</li><div>Pulse</div>");
}
$('ul li:odd').addClass('zebra_odd');
$('ul li:even').addClass('zebra_even');
$("li").click(function(){
$(this).toggleClass("active");
$(this).next("div").stop('true','true').slideToggle();
});
}
});
});
This works quite nicely:
example: http://jsfiddle.net/PWAXt/