我得到了错误jquery.min.js:4 POST http://localhost/Speakertest/index.php/Welcome/ajax 500 (Internal Server Error)
我正在代码点火器中调用ajax函数。
添加查询后,我将得到错误的https://i.imgur.com/4kDJSQf.png
这是我的ajax函数代码
    public function ajax()
{
    $size="";
    $eprice="";
    $size = $this->input->post('size');
    $sprice = $this->input->post('sprice');
    $eprice = $this->input->post('eprice');
    var_dump($size);
    var_dump($sprice);
    var_dump($eprice);
      $query = $this->db->query("SELECT * from info_user Where user_status ='1'"); 
                  if(!empty($size)){
                      $query  .= $this->db->query(" and city in('$size')"); 
                  }
                  if(!empty($sprice) && !empty($eprice)){
                      $query  .=  $this->db->query(" and charge_per_hour >='$sprice' and charge_per_hour <='$eprice'"); 
                  }
                foreach( $result as $row )
                {
                            echo $row->name; 
                            echo $row->charge_per_hour; 
                            echo $row->city; 
                 }
}这是生成错误的行。
$query = $this->db->query("SELECT * from info_user Where user_status ='1'"); 
                  if(!empty($size)){
                      $query  .= $this->db->query(" and city in('$size')"); 
                  }
                  if(!empty($sprice) && !empty($eprice)){
                      $query  .=  $this->db->query(" and charge_per_hour >='$sprice' and charge_per_hour <='$eprice'"); 
                  }
                foreach( $result as $row )
                {
                            echo $row->name; 
                            echo $row->charge_per_hour; 
                            echo $row->city; 
                 }这是我的ajax调用
 $.ajax({
            url:"http://localhost/Speakertest/index.php/Welcome/ajax",
            type:'post',
            data:{size:size,sprice:ui.values[ 0 ],eprice:ui.values[ 1 ]},
            success:function(result){
                $('.product-data').html(result);
            }
        });删除mysql查询之后,它就可以正常工作了。如何消除http://localhost/Speakertest/index.php/Welcome/ajax 500后的错误(内部服务器错误)
发布于 2018-04-18 10:10:45
使用以下内容更改代码
    $query = "SELECT * from info_user Where user_status ='1'"; 
    if(!empty($size)){
        $query  .= " and city in('".$size."')"; 
    }
    if(!empty($sprice) && !empty($eprice)){
        $query  .=  " and charge_per_hour >='".$sprice."' and 
        charge_per_hour <='".$eprice."'"; 
    }
     $result = $this->db->query($query);
     foreach( $result as $row )
     {
         echo $row->name; 
         echo $row->charge_per_hour; 
         echo $row->city; 
     }https://stackoverflow.com/questions/49896842
复制相似问题