【问题标题】:Bootstrap Modal and Jquery Address ajax redirection timing issueBootstrap Modal 和 Jquery Address ajax 重定向计时问题
【发布时间】:2014-12-02 19:18:55
【问题描述】:

我有一个使用 ajax 加载页面主要内容的网络应用程序。我正在使用 jquery 地址来处理使用 ajax 的导航。我有一个显示在模式中的表单,并且在成功提交后,我想将用户重定向到新页面。代码如下:

//called when form is submitted
$('#modal-form').on('submit', 'form', function (e) {
    e.preventDefault();
    var url = $(this).attr('action');
    var data = $(this).serialize();
    var method = $(this).attr('method');
    $.ajax({
        url: url,
        data: data,
        dataType: 'html',
        method: method
    }).fail(function (xhr, status, err) {
        // Check for 401 unauthorized
        if (xhr.status === 401) window.location = '/auth/login/';
    }).done(function (data, status, xhr) {

        $('#modal-form').modal('hide');  //Hide the modal
        redirect(xhr);   //Redirect to a new page
    });
});

现在,问题是在模态完全隐藏之前,页面重定向发生,导致它变黑且无法访问。我也尝试将重定向调用移动到完整的函数中,但似乎不起作用。如果您需要任何其他信息,请告诉我。

【问题讨论】:

标签: jquery twitter-bootstrap jquery-address


【解决方案1】:

模态结束后,您必须使用模态回调来运行重定向:

$('#modal-form').on('hidden.bs.modal', function (e) {
    redirect(xhr);
});

【讨论】:

  • 大概你可以链接$('#modal-form').modal('hide').on('hide.bs.modal', function (e) {...}),还是反过来呢?
  • 我试过了,但似乎不起作用,在模式完全关闭之前调用重定向导致屏幕无法访问。
  • 我误读了文档,它应该在隐藏效果之后发生隐藏,请参阅我的编辑。
猜你喜欢
  • 1970-01-01
  • 2015-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
相关资源
最近更新 更多