简体   繁体   中英

how to reload Bootstrap 3 modal in javascript

I have a Bootstrap Modal that confirm an action in the database by ajax call, i want to reload this modal after return success in ajax.

html:

<div class="modal fade" id="modal-4">
   <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal">&times;</button>
               <h3 class="modal-title">Order Status</h3>
            </div>
            <div class="modal-body"> 
               <label class="ModalArrow">Order Number</label>
                    <select class="SelectStyle" style="width:95%;" name="OrderId" id="OrderId">
                        <option value="">Select Order Number</option>
                            <!--populate value using php-->
                            <?php
                                 $stmt ="SELECT distinct Order_ID FROM orders where Delivered=0";
                                 foreach ($conn->query($stmt) as $row) {
                            ?>
                            <option value="<?php echo $row['ID'];?>"><?php echo $row['Order_ID'];?></option>
                            <?php
                                }
                            ?>
                   </select>
           </div>
           <div class="modal-footer">
                 <button type="button" class="btn btn-success btn-md" style="margin:0;width: 100px;" onclick="ConfirmDelivery()">Delivered</button>
                 <button type="button" class="btn btn-secondary btn-md" data-dismiss="modal" style="font-weight: bold;">Cancel</button>
           </div>
    </div>
</div>

Javascript:

function ConfirmDelivery()
{
  select=document.getElementById("OrderId");
  OrderId=select.options[select.selectedIndex].text;

if (OrderId == "Select Order Number")
{
    sweetAlert("","Please Choose Order Number","error");
    return false;
}

$.ajax({
    type:"POST",
    url:"ConfirmDelivery.php",
    data:"OrderID="+ OrderId ,
    success: function(data)
    {
        if (data == "Success")
        {
            sweetAlert("Order Number:" + OrderId + " has been delivered!");
            $('#modal-4').on('hidden', function() {
                $(this).removeData('modal');
            });
        }
    }
})
}

The problem is that the combo box is not reloaded

from jQuery API

Description: Remove a previously-stored piece of data.

To change content of div#modal you can use .text() or .html() methods depends on your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM