我在codeigniter项目中使用jQuery-ui自动完成功能。但源值不起作用! 这是我的代码。你能帮助我吗? 非常感谢
我的js文件:
$(function() {
$( "#tags" ).autocomplete({
source: "basic_controller/livesearch"
});
});
我的controller
:
class Basic_controller extends CI_Controller {
function __construct() {
parent::__construct();
} //end constructor
public function livesearch()
{
$search = 'a';
$query = $this->turn_model->livesearch($search);
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] =
htmlentities(stripslashes($row['firstName'].''.$row['lastName']));
}//end foreach
}//end if
echo json_encode($row_set); //format the array into json data
}//end of livesearch method
}//end of class
和我的模特
class Turn_model extends CI_Model{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function livesearch($search)
{
$this->db->like("firstName",$search);
$this->db->or_like("lastName",$search);
$query = $this->db->get("user_table");
return $query ;
}
}
答案 0 :(得分:0)
更改您的回音以返回。我不知道这是否有所作为,但api期望它被退回,这将是我尝试的第一件事。