select2在codeigniter中不起作用。我想在下拉列表中显示所有项目数据并手动搜索。为此,我使用了select2 JQuery。下面的代码是:
视图文件中的问题。当我在控制器上发送数据时。当我直接致电控制器时,该功能正常工作
视图
<script type="text/javascript">
$(document).ready(function(){
$('.searchingBook').select2({
placeholder: 'Masukkan ID Buku',
//minimumInputLength: 1,
allowClear: true,
ajax:{
url: "<?php echo base_url(); ?>/test/search_book",
dataType: "json",
delay: 250,
data: function(params){
return{
booksClue: params.term
};
},
processResults: function(data){
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id_book,
text: item.id_book
});
});
return{
results: results
};
}
}
});
});
</script>
<table>
<tr>
<td><b>ID Buku</b></td>
<td> : </td>
<td>
<select class="searchingBook" style="width: 500px">
<option></option>
</select>
</td>
</tr>
</table>
<br><br>
控制器,这是我的控制器的控制器
function search_book(){
$booksClue = $this->input->post('booksClue');
$this->load->model('test_model');
$data_book = $this->test_model->get_book($booksClue, 'item_name');
echo json_encode($data_book);
}
模型,这是我的模型
function get_book($booksClue, $column){
$this->db->select($column);
$this->db->from('items');
$this->db->like('item_name', $booksClue);
return $this->db->get()->result_array();
}
预先感谢谁能解决我的问题