【问题标题】:Fancybox, only refresh parent page after submit, but not on closeFancybox,提交后仅刷新父页面,但不关闭
【发布时间】:2014-01-06 04:34:01
【问题描述】:

我有一个 Fancybox 表单 (iframe)。当用户提交表单时,我让它刷新父页面。但是如果用户决定关闭Fancybox表单而不提交,父页面的刷新仍然在发生。

这是我喜欢的盒子代码:

<script language="JavaScript"> 
$(document).ready(function() {
    $(".edit_product").fancybox({
        autoScale   : true,
        fitToView   : false,
        autoSize    : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        title       : '',
        type        : 'iframe', 
        afterClose  : function () {
                parent.location.reload(true);
        }               
    });
});
</script>

这是提交代码:

<script type="text/javascript"> //EDIT PRODUCT
$(document).ready(function() { 
    var options = { 
        target:        '',
        dataType:      'html',          
        beforeSubmit:  showRequest_editprod,        
        success:       showResponse_editprod
    }; 

    $(".edit_product_div").delegate("#edit_product_form","submit",function () {
        $("#edit_product_loading").show(500);
        $(this).ajaxSubmit(options); 
        return false;
    });

});
function showRequest_editprod(formData, jqForm, options){
    return true; 
}
function showResponse_editprod(responseText, statusText, xhr, $form){       
    parent.jQuery.fancybox.close();
}
</script>

有没有办法在提交后只刷新父页面,如果用户点击“x”或Fancybox之外,它只是关闭fancy box而不刷新?

谢谢。

【问题讨论】:

    标签: php jquery fancybox


    【解决方案1】:

    删除重新加载行:

    afterClose  : function () {
                    parent.location.reload(true);
            } 
    

    parent.location.reload 将再次加载页面。

    像这样为成功函数添加重载代码

    function showResponse_editprod(responseText, statusText, xhr, $form){    
        parent.location.reload(true);
    }
    

    【讨论】:

    • 删除该行也将阻止父页面在表单提交后重新加载。
    • 你可以在submit函数中编写这段代码,而不是onclose
    • 从关闭函数中删除重新加载代码并像我一样添加到成功。尝试更新我的结果。
    • 我从 afterClose 中删除了代码,并将您发布的内容添加到 showResponse 函数中,提交后父页面仍然没有重新加载。
    【解决方案2】:
    $(".fancybox").fancybox({
        afterClose : function() {
            location.reload();
            return;
        }
    });
    

    http://fancyapps.com/fancybox/#useful 在第 11 点

    试试看http://jsfiddle.net/EWTxv/

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多