2013-03-25 2 views
3

모달 jQuery 양식을 제출하려고합니다. 몇 가지 개조만으로 사이트에서 코드를 가져 와서 자바 스크립트를 자체 파일로 옮겼습니다.jQuery 모달 양식 제출

저는 AJAX를 통해 시도하고있는 PHP 스크립트에 양식 정보를 전달하는 데 어려움을 겪고 있습니다. 양식의 serializedArray()를 가져올 때 양식의 각 요소에 [object Object]가 표시됩니다. 이 작업을 수행 할 수있을 때까지 PHP 필드를 전자 메일로 단순화했습니다. 이 논리 뒤에있는 논리를 오해하니?

HTML

<div id="dialog-form"> 
     <form id="sign_up_form" name="sign_up_form" method="post"> 
      <fieldset> 
       <label for="name">Name*</label> 
       <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> 
       <label for="email">Email*</label> 
       <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" /> 
       <label for="password">Password*</label> 
       <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" /> 
       <label for="code">Code</label> 
       <input type="code" name="code" id="code" value="" class="text ui-widget-content ui-corner-all" /> 
      </fieldset> 
     </form> 
    </div> 

JQuery와 - bValid은 양식 유효성 검사이며,

$( "#dialog-form" ).dialog({ 
    autoOpen: false, 
    height: 300, 
    width: 350, 
    modal: true, 
    buttons: { 
     "Create an account": function() { 

     var data_string = $("#sign_up_form").serializeArray(); 

     alert(data_string); 

     if (bValid) { 
      $.ajax({ 
       type: "POST", 
       url: url, 
       dataType: "json", 
       data: data_string, 
       success: function(data){ 
        alert(data) 
       } 
      }); 
      $(this).dialog("close"); 
     } 
     }, 
     Cancel: function() { 
     $(this).dialog("close"); 
     } 
    }, 
    close: function() { 
     allFields.val("").removeClass("ui-state-error"); 
    } 
}); 

PHP

if (isset($_POST['email'])) { 
    $jsonReceiveData = $_POST['email']; 
} 
else{ 
    $jsonReceiveData = "didn't pass"; 
} 
echo json_encode($jsonReceiveData); 

답변

6

사용 var data_string = $("#sign_up_form").serialize(); 대신 var data_string = $("#sign_up_form").serializeArray(); 예상대로 작동합니다. serializeArray() 반환 배열이 아닌 쿼리 문자열

.serialize()

+0

적합합니다. 당신은 완벽하게 일했습니다. – Alex