我已经构建了一个AJAX搜索框,但它与平常有点不同。它从另一个网站提要获取信息。
问题在于我无法按搜索值过滤这些结果。
有人可以帮忙吗?
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://3rab-help-9.blogspot.com/feeds/posts/default/?alt=json&callback=?",
data: "{}",
dataType: "json",
success: function (data) {
$('#search').keyup(function() {
var searchField = $('#search').val();
var myExp = new RegExp(searchField);
var da = data.feed.entry;
var output = '<ul class="searchresults">';
$.each(da, function(key, val) {
var content = val.content.$t.replace(/<(.*?)>/g,"").replace(/[\n\r]+/g," ");
if (val.title.$t(myExp) != -1) {
output += '<li>';
output += '<h2>'+ val.title.$t +'</h2>';
output += '<img src="'+ val.media$thumbnail.url+'" alt="'+ val.title.$t +'" />';
output += '<p>'+ content +'</p>';
output += '</li>';
}
});
output += '</ul>';
$('.result').html(output);
});
},
error: function (result) {
console.log("Error");
}
});