简体   繁体   中英

500 (Internal Server Error) while using ajax codeigniter

I am getting error jquery.min.js:4 POST http://localhost/Speakertest/index.php/Welcome/ajax 500 (Internal Server Error)

I am calling ajax function in codeigniter

after adding query I am getting error https://i.imgur.com/4kDJSQf.png

this is my ajax function code

    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; 

                 }
}

this is the lines which generates error

$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; 

                 }

and this is my ajax call

 $.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);
            }
        });

after removing that mysql query it working fine. how to rid that POST http://localhost/Speakertest/index.php/Welcome/ajax 500 (Internal Server Error)

Change your code with this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM