简体   繁体   中英

Fancybox, only refresh parent page after submit, but not on close

I have a Fancybox form (iframe). When the user submits the form, I am having it refresh the parent page. But if the user decided to close the Fancybox form without submitting, the refresh of the parent page is still happening.

this is my fancy box code:

<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>

This is the submit code:

<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>

Is there a way to only refresh the parent page after a submit, and if the user clicks on the "x" or outside of the Fancybox, it just closes the fancy box without refreshing?

Thanks.

Remove the reload line :

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

parent.location.reload will load the page again.

Add reload code to success function like this

function showResponse_editprod(responseText, statusText, xhr, $form){    
    parent.location.reload(true);
}
$(".fancybox").fancybox({
    afterClose : function() {
        location.reload();
        return;
    }
});

http://fancyapps.com/fancybox/#useful at point 11

Try it http://jsfiddle.net/EWTxv/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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