无法使用 Fancybox 获取要通过 AJAX 发布的表单数据
我使用 Fancybox 在单击链接时弹出联系表单。然后它将表单数据 POST 到 php 文件,发出一封电子邮件并返回一条成功消息。
提交表单后,页面重新加载,数据似乎无处可去。如果我在不使用 AJAX 的情况下提交表单,它工作正常,但随后会加载一个新页面。
形式:
<div style="display:none">
<div id="questions">
<form id="question-form" action="" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Item</p> <input type="text" name="item">
<p>Message</p><textarea name="message" rows="6" cols="25"</textarea>
<br/>
<input type="submit" value="Send">
</form>
</div>
</div>
脚本
$("#question-form").bind("submit", function() {
$.fancybox.showActivity();
$.ajax({
type : "POST",
cache : false,
url : "/includes/question-mailer.php",
data : $(this).serializeArray(),
success : function(data) {
$.fancybox(data);
}
});
return false;
});
我做错了什么?
I'm using Fancybox to have a contact form pop up when a link is clicked. Then it POSTs the form data to a php file, an email goes out and a success message comes back.
After I submit my form is that the page reloads and the data seems to go nowhere. If I submit the form without using AJAX it works fine but then loads a new page.
Form:
<div style="display:none">
<div id="questions">
<form id="question-form" action="" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Item</p> <input type="text" name="item">
<p>Message</p><textarea name="message" rows="6" cols="25"</textarea>
<br/>
<input type="submit" value="Send">
</form>
</div>
</div>
Script
$("#question-form").bind("submit", function() {
$.fancybox.showActivity();
$.ajax({
type : "POST",
cache : false,
url : "/includes/question-mailer.php",
data : $(this).serializeArray(),
success : function(data) {
$.fancybox(data);
}
});
return false;
});
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个简单的错误,我将上面的脚本放在自己的
标签中,而不是放在主 fancybox 附加
script
中。我的最终代码是:It was a simple mistake, I was putting the script above in its own
<script>
tags instead of in the main fancybox attachscript
. My final code is: