AJAX成功后如何关闭一个模态窗口

时间:2022-02-21 12:12:03

I have a button which opens a modal but I have prevented the modal close by clicking background or ESC key.

我有一个按钮可以打开一个模式,但是我通过点击背景或ESC键来阻止模式关闭。

My button looks like this:

我的按钮是这样的:

<button data-toggle="modal" data-target="#CompanyProfile"data-backdrop="static" data-keyboard="false">Click </button>

How do I close this modal after $.ajax success using jQuery?

如何在$之后关闭这个模式。使用jQuery ajax成功吗?

I have done a few tests - the modal has closed but the background gets locked, and I cannot do anything until I refresh the page

我做了一些测试-模式已经关闭,但背景被锁定,我不能做任何事情,直到我刷新页面

2 个解决方案

#1


9  

To close bootstrap modal you can pass 'hide' as option to modal method as follows.

要关闭引导模式,您可以将“隐藏”作为模式方法的选项传递给模式方法,如下所示。

$('#CompanyProfile').modal('hide');

Use this code inside ajax success.

在ajax success中使用此代码。

Fiddle Demo

小提琴演示

#2


0  

You can try something like below. Untested but you'll get the idea.

你可以试试下面的方法。未经测试,但你会明白的。

$.ajax({
  url: 'yourscript.php',
  data: $('form#yourForm').serialize(),
  type: 'post'
}).done(function(response) { 
  // trigger modal closing here since ajax is complete.
});

#1


9  

To close bootstrap modal you can pass 'hide' as option to modal method as follows.

要关闭引导模式,您可以将“隐藏”作为模式方法的选项传递给模式方法,如下所示。

$('#CompanyProfile').modal('hide');

Use this code inside ajax success.

在ajax success中使用此代码。

Fiddle Demo

小提琴演示

#2


0  

You can try something like below. Untested but you'll get the idea.

你可以试试下面的方法。未经测试,但你会明白的。

$.ajax({
  url: 'yourscript.php',
  data: $('form#yourForm').serialize(),
  type: 'post'
}).done(function(response) { 
  // trigger modal closing here since ajax is complete.
});