2012-12-20 5 views
0

Django 및 Jquery에서 실행중인 애플리케이션이 있습니다. 아약스를 통해 부트 스트랩 모달 양식을 제출합니다. 양식을 반환하는 오류가 발견되면 서버 측 양식 유효성 검사를 수행합니다. 그렇지 않으면, 내가 표시하고자하는 양식의 내용이있는 html 테이블을 반환합니다. 하지만 프론트 엔드에서 서버가 HTML 컨텐트를 리턴 한 것을 폼이나 결과 테이블로 어떻게 알 수 있습니까?Jquery : 아약스를 통한 양식 제출 확인 방법

$('#id_form').live("submit", function(e){ 
    e.preventDefault(); 
    form = $(this); 
    frequest_id= form.attr('data-frequest-id'); 
    submitForm('#myModal', form, frequest_id); 
}); 


function submitForm(target, form, frequest_id){ 
    $.ajax({ 
     url:form.attr('action'), 
     type:'post', 
     data:form.serialize(), 
     dataType:"html", 
     error:function(data, status, xhr){ 
      Error(); 
      LoadingDone(); 
     }, 
     beforeSend:function(){ 
      Loading(); 
     }, 
     success:function(data, status, xhr){ 
      $(target).modal(data); 
        //if form has submitted call method to add result to the div 
     }, 
     complete:function(){ 
      LoadingDone(); 
     } 
    }); 
} 

답변

2

jQuery의 .is() method을 사용할 수 있습니다.

success:function(data, status, xhr){ 
    $(target).modal(data); 
    if ($(data).is('form')) { 
     //if form has submitted call method to add result to the div 
    } 
} 
+0

고맙습니다. –