结果出错

时间:2017-07-13 06:37:42

标签: php codeigniter

    success: function(response){
                        $('#ul').html("");
                    var obj = JSON.parse(response);


    public function autocomplete(){ 
             $search =  $this->input->post('search');
             $query = $this->get_apartments($search);
             echo json_encode ($query);

        }

        public function get_apartments($search)
          {

             $query = [
                'val'     =>'*',
                'table'   => 'tbl_apartments as apt',
                'where'   => [],
                'orderby' => 'apt.id',
                'orderas' => 'desc',
                'in_value'=> '',
                'like'    => ['likeon' => 'apt.apt_no', 'likeval' => $search]
             ];
             $datasss = [
                ['table' => 'coach as bd' , 'on' => "bd.bd_code = apt.bd_code", 'join_type'=>'inner']
             ];

            $result = $this->common->datasss_with_in($query,$multijoin);




    }
  

当我使用print_r($ result)时;出口;看到结果吧   向我展示结果,但当我评论这条线时,它向我展示   obj是null ...为什么会发生这种情况

2 个答案:

答案 0 :(得分:0)

get_appartments()应返回一些内容: return $result;

所以$ query将获得一个值。

使用

检查您在javascript中收到的内容

console.log(response);

success: function(response) {
   $('#ul').html('');
   for(var $i=0;$i<$response.rows.length;$i++) {
      $('#ul').append('<li>' + response.rows[$i].building_name + '<li>');
   }
}

答案 1 :(得分:0)

我找到了答案,我需要返回$ result [&#39; rows];简单的解决方案cos json不接受完整的案例