weixin_33720186 2014-01-02 15:11 采纳率: 0%
浏览 19

搜索结果未显示

I am facing a problem with showing results on my dynamic search form. The code for jquery is:

     $("#searchterm").keyup(function (e) {
    if (this.value.length > 4) {
        var q = $("#searchterm").val();
        $('#output').text('You typed ' + $(this).val() + '.');
        $.getJSON('http://catalog.api.2gis.ru/search?what=' + q + '&where=москва&version=1.3&key=rujrdp3400&pagesize=50&callback=?',
        function (data) {
            var tmp = {};
            if (data !== undefined && data.result.length !== 0) {
                $.each(json.result,function(i,result) {
                    var type = result.id;
                    if (!tmp[type]) {
                        tmp[type] = [];
                    }
                    tmp[type].push(result);
                    alert(result.id);

                });
                var html = [];
                $.each(tmp, function (key, item) {
                    html.push('<div id=' + key + '><h3 id=' + key + '>' + key + '</h3> <span>');
                    html.push(result.length + '</span><ul id="items">');
                    $.each(result, function (i, val) {

   var isLiked = getItemIdxByIdFromStorage(val.id) != -1;
                        html.push('<li><a href="#" onClick="podcat('+"'"+val.id+"'"+')">'+val.name+'</a></li>');

                    });

                    html.push('</ul></div>');
                });

                $('#results').html(html.join(''));

                $('h3#listings').replaceWith('<h3>Total results: </h3>');

            } else {
                $('#results').html('Nothing found');
            }
        });
    } else {
        $('#results').html('Please type at least 5 characters');
    }
});

I am trying to get result.id and result.name...Please type pizza in the search field.

If anyone can help me please I would really appreciate it. Sorry but my jquery level is low than a beginner.

Also please use my fiddle http://jsfiddle.net/TCYyH/

  • 写回答

1条回答 默认 最新

  • weixin_33719619 2014-01-02 15:49
    关注

    You're requesting a JSONP response from the Web server (as indicated by the &callback=? parameter in the URL), instead of a more traditional JSON response. You should be able to debug your code from here.

    Change your request from:

    $.getJSON('http://catalog.api.2gis.ru/search?what=' + q + '&where=москва&version=1.3&key=rujrdp3400&pagesize=50&callback=?',
    

    To this:

    $.getJSON('http://catalog.api.2gis.ru/search?what=' + q + '&where=москва&version=1.3&key=rujrdp3400&pagesize=50',
    

    To receive a JSON response instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错