doujiu8178 2011-05-14 10:02
浏览 50

带有LinQ过滤器和jQuery tmpl示例的jQuery AJAX请求

We used this script to get, and filter a JSON with 100.000 elements, to make some quick search at user-side, but unfortunately this is not fast enough.

What do you think, how can i make this script run faster?

<script> 
    $(document).ready(function () {
        var data__ = new Array();
        var val__ = new Array();
        var val_sum = 0;


            $.ajax({
                url: 'hotel.php',
                type: 'POST',
                dataType: 'json',
                timeout: 5000,

                beforeSend: function () {

                }, error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.responseText);
                    alert(thrownError);
                    return false;
                },

                success: function (data) 
                {
                    var list = JSLINQ(data)
                       .Where(function(item){ return item.regio == "Afrika"; })
                       .OrderBy(function(item) { return item.name; })
                       .Select(function(item){ return item; });

                    var movies = list['items']

                    var markup = "<tr><td colspan='2'><b>Hotel: </b> ${name}</td><td><b>Régió:</b> ${regio}</td><td><b>Orszag:</b> ${orszag}</td><td><b>Város:</b> ${varos}</td></tr>";

                    /* Compile markup string as a named template */
                    $.template( "movieTemplate", markup );

                    /* Render the named template */
                    $( "#movieList" ).empty();
                    $.tmpl( "movieTemplate", movies ).appendTo( "#movieList" );
                }
            });
            return false;
    });
</script> 

Thanks for the help.

  • 写回答

4条回答 默认 最新

  • dpsr1670 2011-05-15 00:09
    关注

    You are returning items where region indicates "Afrika". Note that spelling of 'Afrika' could be 'Africa' and that you may still get a lot of items even when you get a timeout. In the database, make sure that the table is properly indexed to make the where and orderby as fast as possible.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘