jQuery模态表单提交


jQuery Modal Form Submission

我正在尝试提交一个模态jQuery表单。我从网站上取了很多代码,只做了一些调整,并将javascript移到了自己的文件中。

我正在努力获得表单信息传递给我的php脚本,我正在尝试通过AJAX。当我提取表单的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);

var data_string = $( "#sign_up_form" ).serialize();代替var data_string = $( "#sign_up_form" ).serializeArray();。serializeArray()返回非查询字符串的数组

.serialize ()