【问题标题】:Display bootstrap modal after page refresh using ajax success and setTimeout使用 ajax 成功和 setTimeout 刷新页面后显示引导模式
【发布时间】:2016-01-29 21:03:46
【问题描述】:

我正在尝试在 jQuery ajax 请求的成功功能上刷新页面后显示引导模式。我认为发生的事情是,一旦页面刷新,setTimeout 就会被清除,因此它永远不会触发。我需要页面刷新内容,但也想为用户提供一个显示发生了什么的对话框。

这是我的代码:

$.ajax({
            type: "POST",
            url: '@Url.Action("UpdateVideoUrl", "ManageVideos")',
            data: JSON.stringify(model),
            contentType: 'application/json',
            success: function () {
                location.reload(true);
                $(window).scrollTop(0);
                setTimeout(function () {
                    $("#SuccessModal").modal('show');
                }, 200);

            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(textStatus + ": " + errorThrown + "." + "  Please see above if applicable");
            }
        });

如果我将超时设置为 100,则模式开始显示并且页面刷新并且我失去了模式。有没有办法完成这个任务?

【问题讨论】:

    标签: jquery ajax twitter-bootstrap bootstrap-modal


    【解决方案1】:

    与其刷新页面然后显示模态,我意识到我需要显示模态,当模态关闭时,触发location.reload(true).animate 命令:

    //Put page to on refresh
    $(document).ready(function () {
        $("html,body").animate({ scrollTop: 0 }, 100); //100ms for example
    });
    
    //Refresh page after modal dialog is closed
    function ReloadPage() {
        location.reload(true);
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 2015-10-19
      • 2019-06-03
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 2017-10-25
      相关资源
      最近更新 更多