简体   繁体   English

如何在自动完成中禁用jquery加载

[英]How to disable jquery loading in autocomplete

I have many pages and many content with jqgrid i give jquery loading in my pages 我有很多页面和许多内容与jqgrid我在我的页面中加载jquery

but, i want jquery loading not show in input autocomplete 但是,我希望在输入自动完成时不显示jquery加载

this my screenshot pages content with jqgrid 这是我的截图页面内容与jqgrid

在此输入图像描述 and this my screenshot jquery loading in input autocomplete 这是我的截图jquery加载输入自动完成

在此输入图像描述

I want jquery loading not show in input autocomplete :( 我希望jquery加载不显示输入自动完成:(

This my code jquery loading in scriptJS.php 这是我在scriptJS.php中加载的代码jquery

<script>
    var showLoader = true;
    $( document ).ajaxStart(function() {
        showLoading( "show" );
    });
    $( document ).ajaxComplete(function() {
        showLoading( "remove" );
    });

    function showLoading( type )
    {
        if( showLoader === true)
        {
            if( type == "show" )
            {
                var html = '<div id="loadingAnimate" style="width:100%;height:100%;z-index:999999;background-color: rgba(0, 14, 30, 0.6);position:fixed;display:block;top:0;left:0;-moz-box-shadow: 1px 1px 6px #000000;-webkit-box-shadow: 1px 1px 6px #000000;box-shadow: 1px 1px 6px #000000;" >';
                    html += '<div style="background-color:#FFF;position:absolute;left:45%;top:30%;width:125px;height:150px;border-radius:8px" id="loadBar" >';
                    html += '<img width="75" style="margin-left:25px;margin-top:25px;margin-bottom:10px;" src="img/preloader.gif" />';
                    html += '<span style="margin-top:15px;font-size:15px;margin-left:23px;color:#34495E"><b>Please Wait</b></span>';
                    html += '</div>';
                    html += '</div>';

                $('body').append(html);
                $( "#loadingAnimate" ).fadeIn( "slow" );
            }
            else if( type == "remove" )
            {
                setTimeout(function(){ 
                    $('#loadingAnimate').fadeOut( "slow" ); 
                    $('#loadingAnimate').remove(); 
                }, 1200);           
            }
        }
        else
        {
            showLoader = true;
        }
    }
</script>

And this one of code jquery autocomplete 而这个代码jquery自动完成

//Autocomplete Vendor Name
                        $( "#vendor_name" ).autocomplete({
                        source: function( request, response ) {
                        $.ajax({
                                url: "autoComplete.php?type=vendor_id",
                                dataType: "json",
                                data: {
                                        term: request.term
                                },
                                success: function( data ) {
                                        response( data );
                                }
                        });
                },
                            minLength: 2,
                            select: function( event, ui ) {
                                    $( "#vendor_name" ).val( ui.item.label );
                                    $( "#vendor_id" ).val( ui.item.name );

                                    return false;
                            },
                            open: function() {
                                    $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
                            },
                            close: function() {
                                    $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
                            }
                    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                        .data( "ui-autocomplete-item", item )
                        .append( "<a>" + item.label+ "</a>" )
                        .appendTo( ul );
                };

*Note : i include scritpJs.php to all pages *注意:我在所有页面中都包含scritpJs.php

Help me, Thank's :) 帮帮我,谢谢:)

try with beforeSend in the ajax of the autocomplete: 在自动完成的ajax中尝试使用beforeSend

beforeSend : function(){
   showloader = false;
}

like as below: 如下所示:

    source: function(request, response) {
      $.ajax({
        url: "autoComplete.php?type=vendor_id",
        dataType: "json",
        beforeSend: function() { // add this
          showloader = false; // change to false
        },
        data: {
          term: request.term
        },
        success: function(data) {
          response(data);
        }
      });
    },

May be you should set showLoader = false (or use some other variable), when using autocomplete? 可能是你应该设置showLoader = false(或使用其他一些变量),使用自动完成时? And then set it back to true, when it's done. 然后将其设置为true,当它完成时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM