2012-10-30 3 views
1

다음 양식을 실제로 사용하는 양식을 검증하는 아약스 코드를 작성했습니다. 그러나 폼을 다시 열었을 때 닫기를 클릭하거나 저장하면 값이 그대로 유지됩니다.jquery 및 codeigniter 모달 폼 유효성 검사 후 트위터 부트 스트랩이 닫히지 않음

<script> 

$(function() { 

    $("#submit_button").click(function(e) { 
     e.preventDefault(); 


     var name = $("input[name=name]").val(); 
     var amount = $("input[name=amount]").val(); 
     var model = $("select[name=model]").val(); 
     var brand = $("select[name=brand]").val(); 

     $.ajax({ 
       type: "POST", 
       url: "<?=base_url()?>index.php/items/create", 
       cache: false, 
       dataType: "json", 
       data: 'name='+name+'&amount='+amount+'&model='+model+'&brand='+brand, 
       success: function(result){ 
        if(result.error) { 
      $(".alert").fadeIn('slow'); 
      $("#error_message").html(result.message); 
      } else {    
      $(".alert").fadeIn('slow'); 
      $("#error_message").html(result.message); 
      $('#new_item').modal('hide') 
      } 

       } 
     }); 

    }); 
}); 

</script> 

이 컨트롤러 코드 : 다음은 내 코드입니다

public function create() 
    { 
     //creating the required validation fields 
     $this->form_validation->set_rules('name', 'Name', 'trim|required'); 
     $this->form_validation->set_rules('brand', 'Brand', 'trim|required'); 
     $this->form_validation->set_rules('amount', 'Amount', 'trim|required|numeric'); 

     $result = array(); 

     if ($this->input->is_ajax_request()) 
     { 

      if ($this->form_validation->run() == FALSE) { 
       $result['error'] = true; 
       $result['message'] = validation_errors(); 
      } else { 

       $result['error'] = true; 
       $result['message'] = 'The record has been saved';   

       $this->m_items->create();    
       redirect('items/index', 'refresh'); 
      } 

      $json = json_encode($result); 
      die($json); 
     } 
     else 
     { 
      redirect('items/index', 'refresh'); 
     } 
    } 

두 번째 문제는 내가 저장을 클릭 한 후, 양식을 항목이 데이터베이스에 구성되어 있지만 메시지가 표시되지 않는 것입니다 그 자리에 남는다. 그런 다음 페이지를 수동으로 새로 고침하고 수행해야합니다.

어떤 사람이 친절하고 나에게 해결책을 줄 수 있습니까 ..... 나는 어느 누구도 될 수있는만큼 감사 할 것입니다!

지금 3 시간 이상 고치려고하는데 도와주세요!

미리 감사드립니다.

답변

0

비우지 않기 때문에?

$("input[name=name]").val(""); 
+0

좀 더 도와 주실 수 있습니까? 또한 저장을 클릭하면 데이터가 저장되지만 모달은 닫히지 않습니다. (도움을주십시오 !! – olbanana

관련 문제