收到ajax的结果后打开一个弹出框

我有一个正常工作的ajax代码,并给出了所需的结果。 我想修改这段代码,并希望当从ajax收到回复时,弹出/模态框应该打开。

我只需点击一下按钮即可打开弹出/模态框

    

但不知道如何在ajax中自动打开它。

这是我的ajax代码

 $.ajax({ type: 'post', url: 'test2.php', dataType: 'json', data: { txt: txtbox, hidden: hiddenTxt }, cache: false, success: function (returndata) { if (returndata[4] === 1) { // want to load a popup box here } else { // other code } }, error: function () { console.error('Failed to process ajax !'); } }); 

任何人都可以告诉我如何做到这一点

你可以使用$("#bsModal3").modal('show'); 在你的结果中。

查看有关模态方法的更多信息

 $.ajax({ type: 'post', url: 'test2.php', dataType: 'json', data: { txt: txtbox, hidden: hiddenTxt }, cache: false, success: function(returndata) { if (returndata[4] === 1) { $("#bsModal3").modal('show'); } else { // other code } }, error: function() { console.error('Failed to process ajax !'); } }); 
      

尝试将此内置成功回调:

 success: function (returndata) { if (returndata[4] === 1) { $('#bsModal3').modal(); // this } else { // other code } }, 

请使用Ajax Call,在ajax响应中调用modal

 $.ajax({ type: 'post', url: 'test2.php', dataType: 'json', data: { txt: txtbox, hidden: hiddenTxt }, cache: false, success: function (returndata) { if (returndata[4] === 1) { $('#bsModal3').modal(); // Please right this in your Code } else { // other code } }, error: function () { console.error('Failed to process ajax !'); } });