2013-03-22 1 views
2

id가 "yearbookorder"인 div가 있는데 숨겨져 있습니다. 클릭 이벤트 후 해당 yearbookorder ID DIV와 함께 colorbox가 나타납니다. 이 사업부에서 jquery colorbox form submit 이벤트가 트리거되지 않았습니다.

, 여기에 코드입니다 : 내가 제출 JQuery와 아약스 코드가

<form id="yearbook_order" name="yearbook_order" action="yearbook/order" enctype="multipart/form-data" method="post"> 
    <input class="ordering" name="yb_email" value="" > 
    <input type="submit" id="order" name="order" value="Send it!"> 
</form> 

하지만, 양식 제출 이벤트가 트리거되지 않습니다

$(function() 
    { 
     $("#yearbook_order").submit(function(e){ 
     e.preventDefault(); 
     dataString = $("#yearbook_order").serialize(); 
     $.ajax({ 
      type: "POST", 
      url: "yearbook/order", 
      data: dataString, 
      dataType: "json", 
      success: function(data) 
      { 
       if (data.status == 'error') 
       { 
        alert(data.message); 
        //$("#msg").html(data.message); 
       } 
       else 
       { 
        //$("#msg").html(data.message); 
        alert(data.message); 
       } 
      } 
      });    
     }); 
    }); 

내가 클릭하면 제출 버튼을 클릭하면 양식이 제출되지 않습니다. 하지만 왜? 컬러 박스가 아닌 빈 페이지에서이 양식을 호출하면 작동합니다. 숨겨진 yearbookorder DIV에 문제가 있습니까?

+0

문제는 AJAX 호출이 작동하지 않는다는 것입니다. –

+0

아니요, 경고를 보낼 때 ("successfull submit); preventdefault 다음의 줄도 트리거되지 않습니다 .AJAX 호출이 작동하지 않습니다. –

+0

문제가 다른 곳에서 발생 했으므로 잘 작동합니다. http://jsfiddle.net/4gJXc/2/ –

답변

1
You are binding submit to the form before it exists. Bind the event to the document, and pass the form selector to .on: 

$(document).on("submit", "#yearbook_order", function(e){ 
    // make ajax request here 
}); 
+0

$ (처리기)는 $ (문서)에 대한 속기입니다. .ready (function() {}) 또한, .on()은 더 이상 사용되지 않습니다 http://api.jquery.com/ready/ –

+0

@MikeC는 더 명확 할 수 있습니까? –

+0

최신 칼 orbox, 정말 오래된 코드를 사용했습니다. 이제 완벽하게이 코드로 작업하고 있습니다! 고맙습니다! –