질문 Q #12761
ajax 로 보낸 값 ci Validation 체크문제
하하예에 2016-01-13 15:07:37
js 파일    
$.ajax({
      url: BASE+"/brd/ajax_ment_insert",
      dataType: "json",
      data: myForm,
      cache: false,
      contentType: false,
      processData: false,
      type: 'POST',
      success: function(obj) {

      },
      error:function(e){
        alert(e.responseText);
      }
    });

 

 

controller  
public function ajax_ment_insert() {
    $a_prm = $this->input->post();
    // Validation
    $this->load->library('form_validation');
    $this->form_validation->set_rules( 'v_ment_cont', 'v_ment_cont', 'required',
      array('required' => '내용이 입력되지 않았습니다.'));
    $this->form_validation->set_rules( 'v_ment_pwd', 'v_ment_pwd', 'required',
      array('required' => '비밀번호 입력되지 않았습니다.'));
    // Check
    if ( $this->form_validation->run() == FALSE ) error_alert();
 }

 

 

input
<input type="text"  id="v_ment_name" name="v_ment_cont" />
<input type="password"  id="v_ment_pwd" name="v_ment_pwd"  />

 

 

테스트할때는 post로 값이 잘 넘어가는걸 확인했습니다. 근데 값 없이 보내니 아무런 반응이 없는데 뭘 빠트린걸까요?

 

답변 3
#1 한대승(불의회상) 2016-01-13 15:13:27

아무런 반응이 없는것이 맞습니다.

$this->input->post() 값이 null 인지 확인 하여 에러메시지를 출력 하도록 하시면 됩니다.

#2 하하예에 2016-01-13 15:30:24

감사합니다.ㅣ^^

#3 2016-01-13 17:33:14

//하하예에

제가 사용하는 코드인데 도움이 될거같아서 팁에 올렸습니다..

http://www.cikorea.net/tip/view/2078/page/1