我需要一些帮助搞清楚我在做什么错误。 我试图来用我的数据库用户的下拉列表。 我使用笨和萤火虫是给我的错误:
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>
CONTROLLER
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"}]