如何在ajax成功中打开bootstrap模式

我想通过jquery打开bootstrap模式。 我知道ajax在运行成功时会发出警报。 但无法打开模态。 这些是我的代码。

$.ajax({ type: "POST", url: "", data: { 'apiName': apiName, 'api': api, 'hotel': hotel, 'payment':payment, 'template': template }, success: function(msg) { $("#getCodeModal").modal("toggle"); $("#getCode").html(msg); } }); 

我的模态HTML是:

    

在控制台中出错:模态不是函数。

试试这个

 success: function(resp){ $("#getCode").html(resp); $("#getCodeModal").modal('show'); } 

试试这个:

 success: function(data) { $("#getCode").html(data); jQuery("#getCodeModal").modal('show'); } 

这应该工作:)。

当你包含两次库jquery时会发生这种情况。 检查一下,也许你将它包含在你的索引中,然后在你的部分页面中再次不必要。