JQuery 已选择:不在后台更新 Select 选项
JQuery Chosen: Not Updating Select Option In Background
我正在使用 JQuery Chosen 插件来设计我的 select 选项。插件本身工作正常。然而,我的一些下拉菜单使用 AJAX POST 来过滤/拉回另一个 Select.
中的精致选项列表
JQuery 插件已添加且未更改。但是出于某种原因,当我 select Select 中的一个选项过滤了次级 select 时,次级 select 似乎没有识别出一个选项 selected.
有什么想法吗?以前有人遇到过这个问题吗?
<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:
$('#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>');
}
});
我以前有过这个,不知道为什么,但是像下面这样的 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>');
}
});
我正在使用 JQuery Chosen 插件来设计我的 select 选项。插件本身工作正常。然而,我的一些下拉菜单使用 AJAX POST 来过滤/拉回另一个 Select.
中的精致选项列表JQuery 插件已添加且未更改。但是出于某种原因,当我 select Select 中的一个选项过滤了次级 select 时,次级 select 似乎没有识别出一个选项 selected.
有什么想法吗?以前有人遇到过这个问题吗?
<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:
$('#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>');
}
});
我以前有过这个,不知道为什么,但是像下面这样的 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>');
}
});