如何在删除请求后重新加载模态数据?

时间:2018-09-13 08:59:17

标签: javascript php jquery ajax bootstrap-modal

我正在表中的引导模式/弹出窗口中显示数据。当我删除一条记录时,该记录会从数据库中删除,但是在请求成功时该表不会刷新。 如何针对每个删除请求以模式方式重新加载数据?

enter image description here

Ajax JS:

    $("a.remedy-row-delete").click(function(e) {
        e.preventDefault();
        var remedy_id = $(this).attr('data-id');
        var dataString = '&id='+remedy_id;
        $.SmartMessageBox({
            title: "Delete Remedy",
            content: "Remedy Entry will be deleted, are you sure ?",
            buttons: "[YES][NO]"
        }, function (ButtonPress) {
            if (ButtonPress === "YES"){
                $.ajax({
                    type: 'POST',
                    data: dataString,
                    url: '<?php echo $this->CxHelper->Route('eb-admin-delete-linked-remedy-from-symptom') ?>',
                    success: function(data) {
                        $("#deleteMessage").show().delay(5000).fadeOut();
                        // Here i want to reload the modal data so that fresh data is loaded
                    }
                });
            }
            else {
                $("a.remedy-row-delete").removeClass('alert');
            }
        });
    });

模式HTML标记:

<div class="modal fade" id="manageRemedyCauseModal" tabindex="-1" role="dialog" aria-labelledby="manageRemedyCauseModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <h4 class="modal-title" id="manageRemedyCauseModalLabel"> Symptom</h4>
         </div>
         <div class="modal-body">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
               ×
               </button>
               <h4 class="modal-title" id="myModalLabel"><strong>Symptom: {{ symptomTitle }}</strong></h4>
            </div>
            <div class="modal-body">
               <div class="alert alert-danger" id="deleteMessage" style="display:none">
                  <strong>Deleted!</strong> Record deleted Successfully.
               </div>
               <div class="row">
                  <div class="col-md-6">
                     <strong>Remedies</strong>
                     <hr>
                     <?php if($remedies){ ?>
                     <table id="cx-records-table" class="table display table-striped table-bordered" width="100%">
                        <thead>
                           <tr>
                              <th>
                                 Title
                              </th>
                              <th>
                                 Delete
                              </th>
                           </tr>
                           <?php foreach($remedies as $key => $remedy){ ?>
                           <tr>
                              <td class="all"><?php echo $remedy['title']; ?><br></td>
                              <td><a class="cx-action remedy-row-delete" href="javascript:void(0)" data-id="{{remedy['id']}}"><i class="fa fa-trash-o"></i></a></td>
                           </tr>
                           <?php } ?>
                        </thead>
                        <tbody></tbody>
                     </table>
                     <?php } else { ?>
                     No records found.
                     <?php } ?>
                  </div>
                  <div class="col-md-6">
                     <strong>Causes</strong>
                     <hr>
                     <?php if($causes){ ?>
                     <table id="cx-records-table" class="table display table-striped table-bordered" width="100%">
                        <thead>
                           <tr>
                              <th>
                                 Title
                              </th>
                              <th>
                                 Delete
                              </th>
                           </tr>
                           <?php foreach($causes as $key => $cause){ ?>
                           <tr>
                              <td class="all"><?php echo $cause['title']; ?><br></td>
                              <td><a class="cx-action cause-row-delete" href="javascript:void(0)" data-id="{{cause['id']}}"><i class="fa fa-trash-o"></i></a></td>
                           </tr>
                           <?php } ?>
                        </thead>
                        <tbody></tbody>
                     </table>
                     <?php } else { ?>
                     No records found.
                     <?php } ?>
                  </div>
               </div>
            </div>
            <div class="modal-footer">
               <button type="button" class="btn btn-default" data-dismiss="modal">
               Cancel
               </button>
            </div>
         </div>
      </div>
   </div>
</div>

我希望我能更好地解释它,让我知道是否需要任何东西。我将提供所有详细信息。

谢谢

0 个答案:

没有答案