jQuery 在 iFrame 中使用 Fancybox Ajax 功能提交表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3511795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:34:40  来源:igfitidea点击:

Submitting form using Fancybox Ajax capabilities within an iFrame

jqueryajaxfancybox

提问by Stanley Ngumo

I would like to use Fancybox to display a registration form within an iFrame. Then once the user has filled in his/her details.

我想使用 Fancybox 在 iF​​rame 中显示注册表。然后一旦用户填写了他/她的详细信息。

The details should be processed using the ajax mechanisms within Jquery/Fancybox and the values displayed within the same Fancybox iframe.

应使用 Jquery/Fancybox 中的 ajax 机制处理详细信息,并在同一 Fancybox iframe 中显示值。

How can this be implemented, I have been scratching my head all day and I dont know where Im going wrong.

这怎么实现,我一整天都在挠头,不知道哪里出错了。

Below is my code

下面是我的代码

$("a.interested").fancybox({
                'width': 400,
                'height': 400,
                'enableEscapeButton' : false,
                'overlayShow' : true,
                'overlayOpacity' : 0,
                'hideOnOverlayClick' : false,
                'type': 'iframe',
                 ajax: {
                           type     : "POST",
                           cache    : false,
                           url      : "/components/profile/buyer/regbuyer1.php",
                           success: function(data) {
                                $.fancybox(data);
                            }
                        }
            });

Some code examples would really help.

一些代码示例真的很有帮助。

Thanx

谢谢

回答by Sue-Jhen Dong

$("a.interested").click(function(){

    $.ajax: {
        type     : "POST",
        cache    : false,
        url      : "/components/profile/buyer/regbuyer1.php",
        success: function(data) {
            $.fancybox({
                'width': 400,
                'height': 400,
                'enableEscapeButton' : false,
                'overlayShow' : true,
                'overlayOpacity' : 0,
                'hideOnOverlayClick' : false,
                'content' : data
            });
        }
    }
});

from http://fancybox.net/blog

来自http://fancybox.net/blog

回答by Ramuns Usovs

The idea would be that you open an iframe in fancybox then in that iframe use regular post as all the requests within the iframe will stay in that iframe.

这个想法是您在fancybox中打开一个iframe,然后在该iframe中使用常规帖子,因为iframe中的所有请求都将保留在该iframe中。

so all you have to do in your code is this:

所以你在代码中要做的就是:

$("a.interested").fancybox({
                'width': 400,
                'height': 400,
                'enableEscapeButton' : false,
                'overlayShow' : true,
                'overlayOpacity' : 0,
                'hideOnOverlayClick' : false,
                'type': 'iframe',
                'href': "/components/profile/buyer/regbuyer1.php" //or any other url that contains the contents of that iframe
            });

回答by David Radcliffe

I believe the ajax options in fancybox are only for loading data, not sending data. You will need to wire up your own ajax post for the form. There is a great example on the fancybox site (http://fancybox.net/blog) example #5. I think this is exactly what you want.

我相信fancybox中的ajax选项仅用于加载数据,而不是发送数据。您需要为表单连接自己的 ajax 帖子。在fancybox 站点(http://fancybox.net/blog)示例#5上有一个很好的示例。我认为这正是你想要的。