2012-11-05 2 views
2

jQuery를 사용하여 하위 iframe에서 부모 창에 포함 된 양식을 제출하는 중입니다. 나는 다음과 같은 검증 기능이 자식 창에서 상위 창 (Ajax 제출)의 내용을 새로 고치지 않고 jQuery를 사용하여 상위 창에서 양식을 제출하는 방법

:

<script type="text/javascript" src="templates/js/jquery.js"></script> 
<script type="text/javascript" src="templates/js/jquery.validate.js"></script> 
<script> 
    $(document).ready(function(){ 
     $("#form_invoice_item").validate({ 
      submitHandler: function (form) { 

       // Check if main invoice already saved 
       if ($('#invoice_id').val() == "") { 

        // Change target to processing iframe 
        try { 
         parent.$('#invoice_form').ajaxSubmit(); 
        } catch(e) { //debug 
         alert ("Error:" + e); 
        } 

       } else { 
        alert ("Saving invoice " + $('#invoice_id').val() + ' items');       } 

       //form.submit(); //debug 
      } 
     });    
    }); 
</script> 
<form method="post" id="form_invoice_item" name="form_invoice_item" action="index.php" target="invoice_items"> 

오류 parent.$('#invoice_form').ajaxSubmit(); 발생이,

Error:TypeError: Object [object Object] has no method 'ajaxSubmit'

난 그냥 일반 자바 스크립트에 다음 코드를 사용하는 경우

입니다 분명히이 문제는 jQuery가 아니지만 작업이 완료된 것입니다. jQuery에서 어떻게합니까 :

parent.document.getElementById('invoice_form').target='process'; 
parent.document.getElementById('invoice_form').submit(); 
parent.document.getElementById('invoice_form').target=''; 

display 속성이 hidden으로 설정된 프로세스라는 숨겨진 iframe이 있습니다.

$('#invoice_form',window.parent.document) 

답변

0

당신은 액세스 오프닝 창에, window.opener를 사용합니다.

이 시도 대신이의

window.opener.$('#invoice_form').ajaxSubmit(); 

을 :

parent.$('#invoice_form').ajaxSubmit(); 

또한 this 게시물을 참조하십시오.

------- 편집 -----

당신이 전화를하는 그 창에 jQuery를 양식 플러그인을로드하는 것을 잊지 마세요 :

<script src="http://malsup.github.com/jquery.form.js"></script>

+0

이것은 팝업 창을 나타내지 않으므로 'window .opener'는 관련이 없습니다. 이것은 iframe과 관련이 있기 때문에'window.document.parent'를 사용하여 부모를 참조하거나'$ (parent) '를 사용해야합니다 –

+0

당신은 제 영웅입니다! 을 추가했습니다. 내 부분에 어리석은 실수. 고마워요 –

+0

좋은 반갑습니다. 감사. 즐겨) –

-1

그냥 부모 선택기를 사용하면 팝업에있는 경우

$(parent).find('#invoice_form').submit(); 
+0

감사 :(아마도 나는 AJA를 연결해야합니다 일부 다른 함수 호출에 의해 양식에 xSubmit 메서드? –

+0

@DeAn 아마도 부모로부터 함수를 실행하려고하기 때문에 부모 자바 스크립트에'ajaxSubmit()'에 대한 코드를 넣어야 할 것입니다 –

0

이 작동합니다 :

+0

@roasted 감사합니다. 객체를 가져 오지만 폼을 제출하지 않습니다. ... 글쎄, 그렇게 보인다 ... 자바 스크립트 오류가 try catch에 잡히지 않았기 때문에 Chrome 브라우저의 관리자에서 네트워크 탭을 확인할 때 아무런 조치도 취하지 않았다. –

0

이것을 시도 .. 개체가 발견되지만 ajaxSubmit()이 객체의 정의 방법은 아닙니다 벤 - 캐리 @

$(parent).find('#invoice_form').submit(); 
관련 문제