我有一个html表单和一个jQuery函数来验证我的表单。
当我将表单值发送到我的php文件时,$_POST
var未设置?
<form id="signup" class="dialog-form" action="bat/new_user.php" method="post">
<div class="form-group">
<label>E-mail</label>
<input type="text" name="mail" placeholder="email@domain.com" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" placeholder="My secret password" class="form-control">
</div>
<input type="submit" class="btn btn-primary">
</form>
PHP脚本是:
if (isset($_POST["mail"]))
{
$mail = $_POST["mail"];
print $mail;}
else{print "ko";
}
JS脚本是:
$( "#signup" ).submit(function( event ) {
event.preventDefault();
var $form = $( this ), url = $form.attr( "action" );
console.log($form.serialize() );
var posting = $.post( url, { s: $form.serialize() } );
posting.done(function( data ) {
$( "#register-dialog" ).append( data );
});
});
我如何获取表单值?
答案 0 :(得分:3)
问题是传递给post()
的数据,它应该是
var posting = $.post(url, $form.serialize());
您正在传递名为s
的参数,其值为序列化表单