- 我正在尝试实现AJAX请求到Codeigniter 4.21路由并将其绑定到select2,结果数据正常,但不会绑定到select2。有任何解决方案吗?**
public function getSpesialis(){
$response = array();
$userlist = $this->spesialisModel->findAll();
$data = array();
foreach($userlist as $user){
$data[] = array(
"id" => $user['id'],
"spesialis" => $user['spesialis'],
);
}
$response['data'] = $data;
return $this->response->setJSON($response);
}
<script>
$('#spesialis').select2({
placeholder: "Pilih Spesialisasi...",
ajax: {
url: '/getspesialis',
type: 'GET',
dataType: 'JSON',
delay: 250,
processResults: function(data) {
return {
results: data
};
}
},
});
1条答案
按热度按时间pprl5pva1#
就用这个...谢谢大家