1

I have spent some time searching but haven't been able to find an answer to this question. When the user peforms some action on my site, a jGrowl message correctly displays. However if the user then refreshes the page, the message unexpectedly redisplays. Also when the user navigates away from the page and then presses the browser's back button, the jGrowl message unexpectedly displays.

I have set a breakpoint in the code and it only gets hit the first time when the jGrowl message is expected to display. Refreshing the page doesn't cause the breakpoint to get hit.

So how do I prevent this unexpected behavior? Thanks for your time.

I would think this is a problem that many people would need a solution for.

<#escape x as x?js_string>
$(function(){

    $("a[name=preview]").fancybox({type:'ajax'});

    // We use jGrowl for the popups that appear in the corner
    $.jGrowl.defaults.closer = false;
    <#if confirmMessage??>
        $("#jgrowlcontainer").jGrowl("${springMacroRequestContext.getMessage(confirmMessage)}");
    </#if>

    // Delete a program
    $('#deleteProgram').click(function(){
        $.fancybox.open('<p>Are you sure you want to delete this program?</p>'+
                        '<button id="deleteProgram">DELETE</button> <button id="deleteCancel">CANCEL</button>');
        return false;
    });
    $("body").on("click","button#deleteCancel",function(){
        $.fancybox.close();
    });
    $("body").on("click","button#deleteProgram",function(){
        $.fancybox.close();
        $('form').attr('action','/build/deleteProgram.html').submit();
        return false;
    });

});
</#escape>
4

1 回答 1

0

我解决了这个问题。当页面刷新时,我实际上可以在代码的不同方法中打断点。此方法看到旧消息仍然具有非空值,并再次将消息添加到模型中,然后前端代码再次显示。为了解决这个问题,我使用了一个标志,该标志在执行应显示消息的操作时设置。然后我使用这个标志有条件地将消息添加到模型中。然后标志被重置。

于 2013-01-24T18:25:20.727 回答