【问题标题】:POST http://localhost/myapp/index.php/myCon/verification 500 (Internal Server Error)POST http://localhost/myapp/index.php/myCon/verification 500(内部服务器错误)
【发布时间】:2017-09-18 07:14:06
【问题描述】:

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

基本网址:

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

【问题讨论】:

  • 您应该启用错误显示和/或检查服务器的错误日志以查看究竟是什么错误。
  • 这段代码中myCon控制器在哪里?
  • @PankajMakwana haha​​h gotot 来改变它。现在浏览我编辑过的代码。
  • 尝试使用 base_url 而不是 site_url...
  • @Mahesh no change 仍然出现相同的错误。

标签: javascript php mysql ajax codeigniter


【解决方案1】:

echo "count:".$res->num_rows(); // 这导致了问题

我在控制器中调用了 num_rows() 函数。在日志文件中出现以下错误:'Severity: Error --> Call to a member function num_rows() on array __'

我已经删除了 echo 语句并且它起作用了。

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 2017-08-17
    • 1970-01-01
    • 2023-02-20
    • 2012-03-16
    • 2021-09-07
    • 2019-02-16
    • 2012-02-23
    • 1970-01-01
    相关资源
    最近更新 更多