2017-09-18 10 views
-1

ユーザーが入力したコードが、AJAXリクエストを発生させたデータベースのコードと同じかどうかを確認しますビューに表示されます。私は同じコードを使用した別の関数でリクエストが送信され、応答が返ってきましたが、ここではエラー 'POST http://localhost/myapp/index.php/myCon/verification 500(内部サーバーエラー)'が発生しています。私はそのエラーの原因を見つけることができません。POST http://localhost/myapp/index.php/myCon/verification 500(内部サーバーエラー)

ベースURL:

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

エラーの表示を有効にするか、サーバーのエラーログをチェックして、エラーが正確であるかどうかを確認する必要があります。 – jeroen

+0

このコードの 'myCon'コントローラはどこですか? –

+0

@PankajMakwana haha​​hはそれを変えるつもりです。さあ、私が編集したコードを見てみましょう。 –

答えて

0

echo "count:" $ res-> num_rows(); //これにより問題が発生しました

コントローラでnum_rows()関数を呼び出しました。 '重大度:エラー - >配列__のメンバー関数num_rows()を呼び出す

私はecho文を削除しています。

関連する問題