2017-04-14 9 views
0

add_bookテーブルの詳細(タイトル)が既に存在するかどうかを確認するためにリモートルールを使用しようとしましたが、次のコードでは結果が得られません... script : -jquery validation remoteがcodeigniterで動作しない

title: { 
     required: true, 
     remote: { 
     url: "<?php echo base_url('add_books/check_title_exists'); ?>", 
     type: "post", 
      } 
     }, 

コントローラー: -

public function check_title_exists() { 
     $title = $this->input->post('title'); 
     $check_title = $this->add_book_model->check_title($title); 
     if ($check_title > 0) { 
      return json_encode(false); 
     } else { 
      return json_encode(true); 
     } 
    } 

モデル: -

public function check_title($title) { 
     $this->db->where('title', $title); 
     $query = $this->db->get('add_book'); 
     if ($query->num_rows() > 0) { 
      return TRUE; 
     } else { 
      return FALSE; 
     } 
    } 

答えて

1

PLE ASE私にとっては、このその作業罰金を試してください: - コントローラ内のスクリプトで

title: { 


required: true, 
          remote: { 
           url: "<?php echo base_url('add_books/check_title_exists'); ?>", 
           type: "post", 
           data: { 
            title: function() { 
             return $("#title").val(); 
            } 
           } 
          } 
         }, 

: -

function check_title_exists(){ 

     $count= $this->add_book_model->isTitleExists($this->input->post('title')); 
      if ($count == TRUE) { 
       echo json_encode(FALSE); 
      } else { 
       echo json_encode(TRUE); 
      } 

    } 
public function isTitleExists($title) { 
      $query = $this->db 
        ->select('title') 
        ->where('title', $title) 
        ->get('books'); 
      if($query->num_rows() > 0){ 
       return TRUE;     
      } else { 
       return FALSE;     
      } 

    } 
+0

最後に、それがうまく機能しています..... you..Ramanjitシンに感謝 –

関連する問題