사용자 도구

사이트 도구


javascript:jquery:form

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
javascript:jquery:form [2012/02/21 11:03]
kwon37xi
javascript:jquery:form [2016/09/02 13:27] (현재)
kwon37xi [jQuery Form Plugin]
줄 17: 줄 17:
 function(){ return $('.myForm').valid(); } function(){ return $('.myForm').valid(); }
 </code> </code>
 +  * form의 submit 버튼을 ''<input type="submit" ../>'' 이나 ''<button type="submit" ...>'' 등으로 할 경우 2 중으로 submit 되는 현상이 발생할 수 있다. 이를 위해 ''onclick="return false;"''를 해당 태그에 추가해주면 된다.
 ==== AjaxForm으로 파일 업로드 ==== ==== AjaxForm으로 파일 업로드 ====
  
줄 28: 줄 28:
 </code> </code>
     * 해당 결과를 jQuery.parseJSON(text); 로 JSON으로 변환하여 그 값을 사용한다.     * 해당 결과를 jQuery.parseJSON(text); 로 JSON으로 변환하여 그 값을 사용한다.
 +
 +=== iframe 옵션과 Cross Domain 문제 ===
 +  * ''document.domain=XX'' 로 Cross Domain 설정을 한 상태에서 iframe 옵션을 사용하면 업로드가 작동하지 않는다. iframe 내부 컨텐츠의 document.domain 설정은 항상 iframe URL의 도메인을 따르게 되기 때문이다. Chrome에서 보면 다음과 같은 오류 발생.<code>
 +Unsafe JavaScript attempt to access frame with URL XXX from frame with URL YYY. Domains, protocols and ports must match.
 +</code>
 +  * 비록 document.domain 설정이 iframe 도메인을 포함한다고 하더라도 두 값이 정확히 동일하지 않으면 작동하지 않게 된다.
 +  * 해결책
 +    * iframe의 결과를 HTML로 하고, 해당 HTML의 <head>에서 **document.domain**을 호출자와 동일하게 설정하는 Javascript 코드를 넣어준다.
 +    * 호출자는 응답 결과를 text나 json이 아닌 **html**로 지정하고, html DOM Parsing을 한다.
 +    * 혹은, 응답 결과를 JSONP로 간주하고, 응답 html에서 callback 호출을 시도해본다.(아직 안해봄)
 +  * [[http://www.sencha.com/forum/showthread.php?136092-Response-lost-from-upload-Ajax-request-to-iframe-if-document.domain-changed|Response lost from upload Ajax request to iframe if document.domain changed]] 참조
 +
 +===== Enter 키로 Form submit 되는 것 막기 =====
 +  * [[http://stackoverflow.com/questions/585396/how-to-prevent-enter-keypress-to-submit-a-web-form|How to prevent ENTER keypress to submit a web form?]]
 +
 +<code javascript>
 +$("form").on("keypress", function (e) {
 +    if (e.keyCode === 13) {
 +        //원하는 작업들..
 +        return false;
 +    }
 +});
 +</code>
 +
javascript/jquery/form.1329789784.txt.gz · 마지막으로 수정됨: 2012/02/21 11:03 저자 kwon37xi