Open a popup box after receiving result from ajax

前端 未结 3 1141
孤城傲影
孤城傲影 2021-01-19 19:15

i have a ajax code that works properly and gives the desired result. I want to modify this code and want that when a reply is received from ajax a popup/modal box should get

相关标签:
3条回答
  • 2021-01-19 20:07

    Try put this inside success callback :

    success: function (returndata) {
        if (returndata[4] === 1) {
            $('#bsModal3').modal(); // this
        } else {
            // other code
        }
    },
    
    0 讨论(0)
  • 2021-01-19 20:11

    You can use $("#bsModal3").modal('show'); inside your result.

    See more about modal methods

    $.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 !');
      }
    });
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
    
    
    
    <!-- Modal -->
    <div class="modal fade" id="bsModal3" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="mySmallModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
            Your content goes here...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

    0 讨论(0)
  • 2021-01-19 20:20

    Please do with the Ajax Call,modal is call in ajax response

    $.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 !');
            }
        });
    
    0 讨论(0)
提交回复
热议问题