简体   繁体   English

选定的JQuery:在后台不更新选择选项

[英]JQuery Chosen: Not Updating Select Option In Background

I am using the JQuery Chosen Plugin to fancy up my select options. 我正在使用JQuery Chosen插件来修饰我的选择选项。 The Plugin itself is working fine. 插件本身运行良好。 However some of my dropdowns use AJAX POST to filter / pull back a refined list of options in another Select. 但是,我的某些下拉菜单使用AJAX POST过滤/拉回另一个Select中精选的选项列表。

The JQuery Plugin, is added and not changed. JQuery插件已添加且未更改。 But for some reason when I select an option in a Select that filters a secondary select, the secondary select doesnt seem to recognise that an option has been selected. 但是由于某些原因,当我在“筛选”中选择一个选项以过滤辅助选择时,辅助选择似乎无法识别出已选择了一个选项。

Any ideas? 有任何想法吗? Has anyone come across this issue before? 有人遇到过这个问题吗?

            <div class="search-line">
                <div class="search-option">
                    <label>Asset Type:</label>
                    <select name="AssetType" id="AssetType">
                        <?php

                        $type_sql = "SELECT DISTINCT AssetType.AssetTypeTitle AS HardwareAssetAssetTypeTitle, HardwareAssetAssetTypeID FROM HardwareAsset INNER JOIN AssetType ON (AssetType.AssetTypeID = HardwareAsset.HardwareAssetAssetTypeID) ORDER BY HardwareAssetAssetTypeTitle ASC";

                        $type = sqlsrv_query($database_connection, $type_sql);

                        if (!sqlsrv_has_rows($type)){
                            echo "<option>No Records Found</option>";
                        }
                        else{
                            echo "<option value= ''>Select Asset Type</option>";
                            while($type_option = sqlsrv_fetch_object($type)){
                                echo "<option value='$type_option->HardwareAssetAssetTypeID'>".$type_option->HardwareAssetAssetTypeTitle."</option>";
                            }
                        }
                        ?>
                    </select>
                </div>
                <div class="search-option">
                    <label>Asset Sub-Type:</label>  
                    <select name="AssetSubType" id="AssetSubType">
                        <option value="">Select Asset Type First</option>
                    </select>
                </div>
            </div>

AJAX: AJAX:

$('#AssetType').on('change',function(){
    var AssetAssetTypeID = $(this).val();
    if(AssetAssetTypeID != 0){
        $.ajax({
            type:'POST',
            url:'/ITSMIS/data/asset/search.php',
            data:'AssetAssetTypeID='+AssetAssetTypeID,
            success:function(data){
                $('#AssetSubType').html(data);
            }
        }); 
    }
    else{
        $('#AssetSubType').html('<option value="">Select Asset Type First</option>');
    }
});

I have had this before, not sure why but doing the onchange like below works for me: 我以前有过这个,不确定为什么,但是像下面这样进行onchange对我有用:

$('body').on('change','#AssetType',function(){
    var AssetAssetTypeID = $(this).val();
    if(AssetAssetTypeID != 0){
        $.ajax({
            type:'POST',
            url:'/ITSMIS/data/asset/search.php',
            data:'AssetAssetTypeID='+AssetAssetTypeID,
            success:function(data){
                $('#AssetSubType').html(data);
            }
        }); 
    }
    else{
        $('#AssetSubType').html('<option value="">Select Asset Type First</option>');
    }
});

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

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