douhui1630
2013-04-16 01:19
浏览 25
已采纳

Bootstrap Select2 - 无法通过AJAX填充

I need some help figuring out what I am doing incorrectly. I am trying to populate the dropdown with users from my database. I am using Codeigniter and Firebug is giving me the error:

TypeError: j is undefined

VIEW

 <input id="users" type="hidden">

 <script>
 $("#users").select2({
        width: "element",
        ajax: {
            url: "localhost/index.php/get_clients",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term
                };
            },
            results: function (data, page) {
                return { results: data };
            }
        }
  });
  </script>

CONTROLLER

function get_clients() {
    $this->load->model('users_model');
    $result = $this->users_model->get_all_clients();
 }

MODEL

 function get_all_clients() {
    $all_clients = $this->db->select('CONCAT(first_name, " ", last_name) as text, id', FALSE)
    ->get('clients')->result();
    $rows = array();
        foreach ($all_clients as $entry) {
            $rows[] = $entry;
        }
        print json_encode($rows);
}

Which returns something like this:

  [{"text":"John Smith","id":"433"},{"text":"Paul Sparks","id":"434"}]
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdqpdjpq16640651 2013-04-16 14:41
    已采纳

    Sorry, I was being stupid. I figured it out. User error.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题