Как перезагрузить модальные данные по запросу на удаление? - PullRequest
0 голосов
/ 13 сентября 2018

Я показываю данные в модале / всплывающем окне начальной загрузки в таблице. Когда я удаляю запись, запись удаляется из базы данных, но таблица не обновляется при успешном выполнении запроса. Как я могу перезагрузить данные в модальном режиме при каждом запросе на удаление?

введите описание изображения здесь

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>

Надеюсь, я объяснил это лучше, дайте мне знать, если что-нибудь потребуется. Я предоставлю все детали.

Спасибо

...