POST http://localhost/myapp/index.php/myCon/verification 500(内部服务器错误)

时间:2017-09-18 07:14:06

标签: javascript php mysql ajax codeigniter

这里检查用户输入的代码是否与我在视图中引发了AJAX请求的数据库中的代码相同。在另一个函数中,我使用相同的代码,在那里发送请求,我收到了响应,但是这里收到错误'POST http://localhost/myapp/index.php/myCon/verification 500(内部服务器错误)'。我无法找到导致该错误的原因。

基本网址:

$config['base_url'] = 'http://localhost/myapp/';

查看:

<script type="text/javascript">
function newPass(){
    var temp = jQuery("#code").val();
    console.log('code:'+temp);
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: "<?php echo site_url(); ?>index.php/myCon/verification", //**getting error here**
        data: {"temp":temp},
        success:function(response){
            console.log("response"+response);
            var msg = response.message;
            var stat = response.status;
            if(stat == 'success'){
                //some statements
            }
            else{
                document.getElementById('msg').innerHTML = 'Incorrect code';
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) { 
            console.log("Status: " + textStatus); console.log("Error: " + errorThrown); 
        }
    });
}
</script>

控制器:

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');  
    /**
    * 
    */
    class MyCon extends CI_Controller
    {
        function __construct() {
            parent::__construct();
        }
        //there is another function in which am calling AJAX request too it is working but am getting error while calling this verification.
        public function verification(){
            if ($this->input->is_ajax_request()) {
                $this->load->model('CustomerModel');
                $res = $this->CustomerModel->checkCode();
                echo "count:".$res->num_rows(); // this caused the problem
                if(!empty($res)) {
                    $data['status'] = 'success';
                    $data['message'] = 'code found';
                } else {
                    $data['status'] = 'error';
                    $data['message'] = 'Data not found';
                }
                echo json_encode($data);
                exit;
            }
            else{
                redirect('index.php/myCon/fp_confirm');   
            }
        }
    }
?>

型号:

<?php
    class CustomerModel extends CI_Model{
        function __construct()
        {
            parent:: __construct();
        }
        function checkCode(){
            $code = $this->input->post('temp');
            $result = $this->db->get_where('privilege_customer', array('code_password' => $code));
            return $result->result();
        }
   }
?>

1 个答案:

答案 0 :(得分:0)

  

echo&#34; count:&#34;。$ res-&gt; num_rows(); //这导致了问题

我在控制器中调用了num_rows()函数。日志文件中出现以下错误:&#39;严重性:错误 - &gt;在数组__&#39;

上调用成员函数num_rows()

我删除了echo语句,但它确实有效。