【问题标题】:jQuery-ui autocomplete in codeigniter not workcodeigniter中的jQuery-ui自动完成功能不起作用
【发布时间】:2014-08-20 14:13:31
【问题描述】:

我在我的 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 ;
 }
}

【问题讨论】:

  • 看起来您总是在搜索“a”,所以我知道为什么没有任何效果。

标签: php jquery codeigniter jquery-ui


【解决方案1】:

更改您的回声以返回。我不知道这是否会有所作为,但 api 期望它被返回,这将是我尝试的第一件事。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 2013-12-23
    • 2018-07-25
    • 2020-10-26
    • 1970-01-01
    • 2012-12-16
    相关资源
    最近更新 更多