1 回答
TA贡献1802条经验 获得超5个赞
响应是一个对象,而不是字符串。您必须访问该属性type_status才能检查该值。
将您的脚本更改为以下内容
<script type="text/javascript">
$( "document" ).ready( function () {
const sale = $( "#sale" );
const lease = $( "#lease" );
// hide both elements at start
sale.hide();
lease.hide();
$( "#property" ).change( function () {
const property_id = $( this ).val();
$.ajax( {
url: '<?php echo base_url( 'admin/Unit/get_type_status' )?>',
type: 'POST',
data: { property_id: property_id },
dataType: 'json',
success: function ( response ) {
console.log( response );
// check the property 'type_status'
if ( response.type_status == "Sale" ) {
lease.hide();
sale.show();
} else {
sale.hide();
lease.show();
}
}
} );
} );
} );
</script>
并使用这个 HTML
<div class="form-group col-md-6">
<label class="control-label">Property Status<span class="manda">*</span> </label>
<div id="sale">
<select class="form-control" name="typeStatus" id="typeStatus">
<option value="0">Choose....</option>
<option value="Available">Available</option>
<option value="Sold">Sold</option>
</select>
</div>
<div id="lease">
<select class="form-control" name="typeStatus" id="typeStatus">
<option value="0">Choose....</option>
<option value="Occupied">Occupied</option>
<option value="Vacancy">Vacancy</option>
</select>
</div>
</div>
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报