我有一个城市字段,在inlineedit调用中,它将在下拉列表中加载ajax数据。请检查我的代码,让我知道我错在哪里。我阅读了 select2 文档
<script type="text/javascript">
jQuery(function($) {
$('#city_id').editable({
type: 'select2',
name: 'otmp_tx_user_details:city_id',
pk:"userdetailid:<?php if($student_info->userdetailid) echo $student_info->userdetailid; else echo "0";?>",
ajax: {
url: "<?php echo site_url()?>students/get_city_by_country",
dataType: 'json',
data: function () {
return;
},
results: function (data) {
return {results: data};
}
},
url: "<?php echo site_url();?>students/inlineedit",
success: function(data) {
}
});
});
</script>
这是我从PHP文件中的ajax数据:
$array = array(
array("id"=>1,text=>"Dhaka"),
array("id"=>2,text=>"Pabna")
);
echo json_encode($array);
请帮助我解决我的问题。
尝试将 Ajax 对象包装在 select2
对象中,如下所示:
jQuery(function($) {
$('#city_id').editable({
type: 'select2',
name: 'otmp_tx_user_details:city_id',
pk:"userdetailid:<?php if($student_info->userdetailid) echo $student_info->userdetailid; else echo "0";?>",
select2: {
ajax: {
url: "<?php echo site_url()?>students/get_city_by_country",
dataType: 'json',
data: function () {
return;
},
results: function (data) {
return {results: data};
}
}
},
url: "<?php echo site_url();?>students/inlineedit",
success: function(data) {
}
});
});