程序go 2019-08-09 08:40 采纳率: 100%
浏览 12

添加负载搜索微调器

I am using Ajax to search for cities and Locations, I am facing two main problems First one the query last 5 seconds that is very slow I didn't know how to add a spinner of waiting while search is happening This is part of the code

 $('#firstadress').autocomplete({
        serviceUrl: '/autosearch',
        onSearchStart: function (suggestion) {
            $(this).addClass('searching');
         /* here where I want to added code */

        },
        onSearchComplete: function (suggestion) {
            $(this).removeClass('searching');
        },

How can I ameliorate this question .

Thanks in advance

  • 写回答

1条回答 默认 最新

  • csdnceshi62 2019-08-09 09:40
    关注

    you need to add loader in search function and remove it in response function which is already present in autocomplete.

    <style type="text/css">
        .loader
        {
            background: url(loader.gif); // you loader url
            background-repeat: no-repeat;
            background-position: right;
        }
    </style>
    
    <script type="text/javascript">
        $(function () {
            $("#txtSearch").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: 'url',
                        data: "{ 'prefix': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split('-')[0],
                                    val: item.split('-')[1]
                                }
                            }))
                        }
                    });
                },
                search: function (e, u) {
                    $(this).addClass('loader');
                },
                response: function (e, u) {
                    $(this).removeClass('loader');
                }
            });
        });
    </script>
    Enter search term: <input type="text" id="txtSearch" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号