我在fancybox 窗口中使用表单将(Ajax)数据发布到php 页面。
如果我在 Fancybox 之外运行表单,它会完美运行。插入 - 检查。响应 - 检查。也就是说,如果我通过 Fancybox 运行相同的页面,我会得到一个加载轮(在我关闭覆盖后仍然存在)。
表格(form_test.php):
<form id="form" method="post" action="">
<input type="text" id="name" name="name" value="Test Name" />
<input type="text" id="email" name="email" value="email@test.com" />
<input type="submit" value="Login" />
</form>
<script type"text/javascript">
$("#form").bind("submit", function () {
$.fancybox.showLoading(); // it was $.fancybox.showActivity(); for v1.3.4
$.ajax({
type: "POST",
cache: false,
url: "test.php", // make sure your path is correct
data: $(this).serializeArray(), // your were using $(form).serialize(),
success: function (data) {
$.fancybox(data);
}
});
return false;
}); // bind
</script>
PHP (test.php):
$name=$_POST['name'];
$email=$_POST['email'];
$query=mysql_query("INSERT INTO members (firstName,email) VALUES('$name','$email')");
if($query){
echo "Data for $name inserted successfully!";
}
else{
echo "An error occurred!";
}
想法?