代码编写器中的jQuery-ui自动完成不工作


jQuery-ui autocomplete in codeigniter not work

我在我的codeigniter项目中使用jQuery-ui自动完成。但是源值不起作用!这是我的代码。你能帮我吗?谢谢你。

my js file:

$(function() {
  $( "#tags" ).autocomplete({
    source: "basic_controller/livesearch"
  });
});

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

将echo改为return。我不知道这是否会产生影响,但是api期望它被返回,这将是我尝试的第一件事。