1

私が間違っていることを理解するのに助けが必要です。データベースからドロップダウンにユーザーを入力しようとしています。Codeigniter を使用していますが、Firebug でエラーが発生します。

TypeError: j is undefined

見る

 <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>

コントローラ

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

モデル

 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);
}

次のようなものが返されます。

  [{"text":"John Smith","id":"433"},{"text":"Paul Sparks","id":"434"}]
4

1 に答える 1

0

すみません、バカでした。私はそれを考え出した。ユーザーエラー。

于 2013-04-16T14:41:43.283 に答える