繁体   English   中英

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

[英]Fancybox sends form data to other php page

这是fancybox的原始脚本

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

我想从以下表单发送数据,通过fancybox iframe脚本将它们发送到“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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM