1

我有一个城市字段,在 inlinedit 调用时它将在下拉列表中加载 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);

请帮我解决我的问题。

4

1 回答 1

1

尝试将 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) {
        }
    });
}); 
于 2013-11-10T23:08:48.863 回答