我需要先选择source_type
,然后它会location
根据source_type
查看文件
<select name="source_type" id="source_type">
<option value="">Source Type</option>
<option value="Internal">Internal</option>
<option value="External">External</option>
</select>
<select name="location" id="location">
<option value="">Select</option>
</select>
$('#source_type').change(function(){
$.ajax({
type: 'post',
data: 'source_type'+$(this).val(),
url: 'get_sources_location',
success: function(data) {
$('#source_location').val(data);
}
});
});
..控制器
public function get_sources_location()
{
$source_type = $this->input->post('source_type');
$this->load->model('documents_model');
$results = $this->documents_model->get_locations();
echo $results;
}
..模型
public function get_locations()
{
$query = $this
->db
->select('location')
->where('classification', $source_type = $this->input->post('source_type'))
->get('sources_location');
$data = array();
foreach ($query->result() as $row)
{
$data = $row->location;
}
return $data;
}