繁体   English   中英

提交表单后关闭Colorbox iframe,然后重定向父页面

[英]Close Colorbox iframe after form submit and then redirect parent page

我一直试图弄清楚这个问题已经有几个星期了,但结果却平平。 由于我缺乏对Jquery的了解和对Java语言的最少了解,我在网上搜集了一些代码,我确信这都是错误的。 我正在使用Colorbox在iframe中显示带有“添加到购物车”按钮的产品(父级和iframe都是来自服务器的页面)。 我想要的结果是:

(为清楚起见进行了编辑)

  1. 使“添加到购物车”按钮在提交时将表单数据传递给父级。
  2. 传递表单后关闭Colorbox iframe。
  3. 父框架提交表单。

到目前为止,我在iframe中已对表单使用以下代码:

<form name="cart_quantity" action="index.php?action=add_product" method="post" 
enctype="multipart/form-data" onSubmit="parent.$.fn.colorbox.close();">
<input type="hidden" name="qty" value="1" /> 
<input type="hidden" name="id" value="7" /> 
<input type="hidden" name="attri" value="17" id="attri-17" />
<input class="cssButton button" type="submit" value="ADD TO CART"/> 
</form>

我在父页面上调用colorbox的脚本是:

<script>
function lightbox(){    
  $.fn.colorbox({ 
  iframe:true,
  onClosed:function(){ window.location = 'index.php?main_page=shopping_cart'; }, 
  href:"./index.php?main_page=product_info&id=7"});
}
</script>

所以到目前为止的问题:

提交表单后,Colorbox将关闭,并且表单仅提交一半的时间(部分成功率)。 我尝试使用firebug跟踪已发布的数据,以查看是否每次都在发布,但是由于它来自iframe,因此似乎什么也看不到。

如果有人可以通过正确的代码帮助我解决问题,我将不胜感激!

您可以尝试添加延迟:

onSubmit="window.setTimeout(function(){parent.$.fn.colorbox.close();}, 150);"

将150更改为确保发送请求所需的任何值。

在此处阅读有关setTimeout的更多信息。

暂无
暂无

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

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