Fancybox将表单数据发送到其他php页面 [英] Fancybox sends form data to other php page

查看:150
本文介绍了Fancybox将表单数据发送到其他php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是fancybox的原始脚本

This is the original script of fancybox

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

我想从以下表单发送数据,将它们发送到go.php页面fancybox iframe脚本

我想通过fancybox在同一/当前窗口中打开go.php

I want to send the data from the following form to POST them to "go.php" page via fancybox iframe script
I want to open "go.php" in the same/current window via fancybox

<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

If I used type="button", fancybox iframe works but POST don't send anything to go.php
If I used type="submit", fancybox iframe doesn't work but POST sends the form data to go.php correctly

推荐答案

当您点击提交按钮时,浏览器不知道你想发送你的表格。

When you're clicking on a 'Submit' button, the browser doesn't know that you want to send your form.

只需使用type =button并更改你的javascript:

Just use type="button" and change your 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>

这篇关于Fancybox将表单数据发送到其他php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆