使用ajax codeigniter时500(内部服务器错误)

时间:2018-04-18 10:03:25

标签: php ajax mysqli internal-server-error

我收到错误jquery.min.js:4 POST http://localhost/Speakertest/index.php/Welcome/ajax 500 (Internal Server Error)

我在codeigniter中调用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查询后,它工作正常。如何摆脱POST http://localhost/Speakertest/index.php/Welcome/ajax 500(内部服务器错误)

1 个答案:

答案 0 :(得分:2)

使用此

更改您的代码
<TextBox Text="{Binding ......>
    <i:Interaction.Behaviors>
        <ui:TextBoxDecimalRangeBehaviour MaxDecimals="2" 
                                         MaxInteger="1" 
                                         Minimum="{StaticResource Zero}" 
                                         Maximum="{StaticResource Ten}" />
        <ui:SelectAllTextBoxBehavior/>
    </i:Interaction.Behaviors>
</TextBox>