$ .ajax调用时,jquery multiselect不刷新

时间:2019-02-04 16:02:46

标签: jquery

我有一种情况,我想在ASP.NET droopdown更改时填充ASP.NET列表框。我已经使用jquery ajax调用绑定了asp.net下拉列表。现在,我想在下拉列表更改后填充Jquery multiselect列表框。当我在列表框上禁用多重选择但不启用多重选择时,它起作用。 以下是我的代码

$(document).ready(function (c) {
    $('.alert-close').on('click', function (c) {
        $('.message').fadeOut('slow', function (c) {
            
            
        });
    });
    
    $("#<%=ddlProcess.ClientID %>").change(function (event) {
        
        // alert($('#MainContent_ddlProcess :selected').text());
        
        //alert();
        
        
        event.preventDefault();
        $('#lstCustomers').multiselect('destroy');
        GetAllServicesByUserAndProcess(2154, $('#MainContent_ddlProcess option:selected').val());
        initMultiSelect();
        
    });
    
    function initMultiSelect() {
        
        $('#lstCustomers').multiselect({
            includeSelectAllOption: true,
            enableFiltering: true,
            enableCaseInsensitiveFiltering: true,
            buttonWidth: 250
        });
    }
    
    
    $('#button').click(function (e) {
        e.preventDefault();
        $('#lstCustomers').multiselect('destroy');
        initMultiSelect();
    });
    
    function GetAllServicesByUserAndProcess(UserID, ProcessID) {
        debugger;
        var reponseLength;
        
        $.ajax({
            type: 'post',
            url: 'DbService.asmx/BindServicesWeb',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            data: JSON.stringify({ UserID: UserID, ProcessID: ProcessID }),
            success: function (response) {
                var lstCustomers = $("[id*=lstCustomers]");
                
                if (response.d.length > 0) {
                    reponseLength = response.d.length;
                    
                    $('#lstCustomers').multiselect('destroy');
                    //alert('hjj');
                    $.each(response.d, function () {
                        //alert('ppu');
                        lstCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
                        //  $('lstCustomers :contains(' + _serviceName + ')').remove();
                        
                    });
                    $('[id*=lstCustomers]').multiselect({
                        
                        enableFiltering: true,
                        enableCaseInsensitiveFiltering: true,
                        buttonWidth: 250
                    })
                    
                    
                    
                }
                else {
                    reponseLength = 0;
                    $('#lstCustomers').multiselect('destroy');
                    //alert('no records');
                    lstCustomers.empty();
                    $('[id*=lstCustomers]').multiselect({
                        
                        enableFiltering: true,
                        enableCaseInsensitiveFiltering: true,
                        buttonWidth: 250
                    })
                }
                
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert('errorThrown : ' + thrownError);
            },
            complete: function () {
                async: true;
                
                //$('[id*=lstCustomers]').multiselect({
                //    includeSelectAllOption: true,
                //    buttonWidth: 250
                //})
                
                
                //setTimeout(function () { notifSent = false; }, 3000);
                // alert('Complete');
                //window.location.reload();
            }
        });
    }
});
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
    <div class="input-group col-xs-2" id="divProcess">
        <label for="ddlService" class="control-label">
            Process Name
        </label>
        <div class="form-group">
            <asp:DropDownList runat="server" Style="width: 250px;" CssClass="chzn-select" ID="ddlProcess" />
        </div>
    </div>
</ContentTemplate>
</asp:UpdatePanel>

<div class="input-group col-xs-2" id="divService">
    <label for="ddlService" class="control-label">
        Service Name
    </label>
    <div class="form-group">
        
        <asp:ListBox runat="server" ID="lstCustomers" SelectionMode="Multiple" />
    </div>
    
</div>

请帮助我解决。我想与InitMultiselect一起使用。如果使用InitMultiselect,而没有InitMultiselect起作用,则该方法不起作用。

0 个答案:

没有答案