2017-04-14 104 views
0

我試圖使用遠程規則來檢查add_book表中的詳細信息(標題)是否已經存在......但使用以下代碼,它沒有給出任何結果...... 腳本: -jquery驗證遠程無法在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辛格 –