0

我正在创建一个搜索栏,用于查询 Facebook 的结果。当我输入一个词进行搜索并单击搜索时,我会得到结果,但任何发布“状态”的人......我都会得到很多未定义的字段。所以它说“'用户'分享了一个状态”,在它下面的照片部分说未定义,并且没有实际状态。它是空白的。我怎样才能解决这个问题?

其他一切都很好......“'用户分享了一张照片”显示了他们分享的照片。还有一个描述......有时。共享链接也可以。

我还希望能够在搜索栏中输入多个单词,并且能够再次搜索。截至目前,您必须刷新页面才能再次搜索。

我检查了其他主题以获得答案,但这些主题不是我进行搜索的方式。我还没有找到答案。希望有人可以提供帮助!谢谢....这是我的搜索栏所在页面的链接。我也会包括我的代码。 http://ericnaff.com/html5/p3/另外-我怎样才能让它“输入/返回”也开始搜索?

代码-

function searchFB(userSearchparameter) {

    $.getJSON('https://graph.facebook.com/search?q=' + userSearchparameter + '&callback=?', function(fbResults){
        $.each(fbResults.data, function() {
            // Data Templating
            $('<article class="fbResults"></article>').append ( 

                '<section class="resultsSource"><h6 class="shareHeader">' +
                '<img class="fromUser" src="https://graph.facebook.com/' + this.from.id + '/picture" height="50" width="50" alt="' + this.from.name + '">' +
                '<a href="http://www.facebook.com/' + this.from.id + '" class="fromName">' + this.from.name +'</a> shared a <a class="typeLink" href="' + this.link + '">' + this.  
                type + '</a> </h6>' +
                '<time class="createdTime" datetime="' + this.created_time + '">' + fuzzyFacebookTime(this.created_time.replace(/-/g,'/')) + ' &middot;</time>' +
                '<img class="typeLinkIcon" src="' + this.icon + '" alt="icon"></section>' +
                '<section class="resultsDescription"><h6><a class="shareLink" href="' + this.link + '">' +
                '<img class="sharePicture" src="' + this.picture + '" height="90" width="90" alt="' + this.name +'">' +
                '<span class="shareName">' + this.name + '</span>' +
                '<span class="shareCaption">' + this.caption + '</span>' +
                '<span class="shareDescription">' + this.description + '</span>' +
                '</a></h6></section>' +
                '<iframe class="linkShare" src="http://facebook.com/plugins/like.php?href=' + this.link + '"></iframe>'
            ).appendTo('body');

            $('.fbResults section.resultsDescription span:contains(undefined)').remove();
        })
    })
}
$("button.startSearch").click(function() {
    var searchThis = $('.searchQuery').val();
    searchFB(searchThis);
});
4

1 回答 1

1

所以我想出了一个解决所有未定义结果的方法。这是我的代码-

$('.fbResults').find('img[src="undefined"]').remove();

我还负责使用ENTER/RETURN来启动该.keypress功能的搜索,就像这样-

$("input.searchQuery").keypress(function(event) {
$('.fbResults').remove();
if (event.which == 13) {                        //enter
event.preventDefault();

该代码还刷新了结果。

感谢您收到的任何帮助。

于 2013-05-28T20:58:48.873 回答