gpt4 book ai didi

javascript - Fancybox发送表单数据到其他php页面

转载 作者:行者123 更新时间:2023-12-02 17:57:38 25 4
gpt4 key购买 nike

这是fancybox的原始脚本

<script>
$(document).ready(function() {
$("#fancybox-manual-b").click(function() {
$.fancybox.open({
href : 'go.php',
type : 'iframe',
padding : 5
});
});
});
</script>

我想从以下表单发送数据,通过 fancybox iframe 脚本将它们 POST 到“go.php”页面
我想通过 fancybox 在同一/当前窗口中打开 "go.php"

<form name="fancy" action="go.php" method="POST">
<input name="text1" type="text">
<input name="text2" type="text">

**<input type="button" value="Submit" id="fancybox-manual-b"/>
**<input type="submit" value="Submit" id="fancybox-manual-b"/>
</form>

如果我使用 type="button",fancybox iframe 可以工作,但 POST 不会向 go.php 发送任何内容
如果我使用 type="submit",fancybox iframe 不起作用,但 POST 可以正确地将表单数据发送到 go.php

最佳答案

当您点击“提交”按钮时,浏览器并不知道您要发送表单。

只需使用 type="button"并更改您的 JavaScript:

<script>
$(document).ready(function() {
$("#fancybox-manual-b").click(function() {
$.post('go.php', $(this).parent().serialize())
.done(function() {
$.fancybox.open({
href : 'go.php',
type : 'iframe',
padding : 5
});
});
});
});
</script>

关于javascript - Fancybox发送表单数据到其他php页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20865640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com