根据你的问题,我理解的是,当选择下拉列表更改时,Codeigniter中的jQuery ajax会自动获得2个或更多输入值。
HTML部分:-
<select name="test" id="test" >
<option value="user1">user1</option>
<option value="user2">user2</option>
<option value="user3">user3</option>
<option value="user4">user4</option>
<option value="user5">user5</option>
</select>
<input type="text" placeholder="Address" id="address"/>
<input type="text" placeholder="Name" id="name"/>
<input type="text" placeholder="Contact" id="contact"/>
JQuery/Ajax部分:-
<script type="text/javascript">
$('#test').change(function(){
var test=$(this).val();
$.ajax({
type: "GET",
url: '<?php echo base_url("index.php/emp_salary/ajaxReq"); ?>',
data: {test:test},
success:function(data)
{
var result = $.parseJSON(data);
$("#address").val(result.address);
$("#name").val(result.name);
$("#contact").val(result.contact);
}
})
});
</script>
控制器部分:-
public function ajaxReq() {
$test = $this->input->post('test');
$value = $this->salary_model->getVal($test);
echo json_encode($value);
}
模型部件:-
public function getVal($test){
$this->db->select('*');
$this->db->from('employee');
$where = array('empId' => $test );
$this->db->where($where);
$query = $this->db->get();
return $query->row_array();
}