删除记录后刷新模态

时间:2018-05-23 17:10:27

标签: javascript php jquery

我有一个bootstrap模式,用于加载用户先前加载的文档列表。每条记录旁边都会显示一个垃圾桶图标(文件为动态内容),表示文档被取消。一切正常但只有在手动关闭模态并重新打开后才能看到更新记录列表。 我希望当用户点击垃圾箱时,模态会动态更新。

模态代码:

$(document).ready(function() {

  $(document).on('click', '#getDocumenti', function(e) {

    e.preventDefault();

    var uid = $(this).data('id'); //ottenere l'id della riga cliccata

    $('#content-dynamic').html(''); //lascia questo div vuoto
    $('#loader-modal').show(); //carica Ajax sul pulsante clic

    $.ajax({
        url: 'temp/amministratore/getdocumenti.php',
        type: 'POST',
        data: 'id=' + uid,
        dataType: 'html'
      })
      .done(function(data) {
        console.log(data);
        $('#content-dynamic').html(''); //vuoto prima del carico
        $('#content-dynamic').html(data); //caricare qui
        $('#loader-modal').hide(); //nascondi caricatore  
      })
      .fail(function() {
        $('#content-dynamic').html('<i class="glyphicon glyphicon-info-sign"></i> Qualcosa è andato storto, prova ancora...');
        $('#loader-modal').hide();
      });

  });
});
<div class="modal fade" id="modalDocumenti" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">


    <div class="modal-content">

      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Ducumenti caricati</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
      </div>

      <div class="modal-body">
        <div id="loader-modal" style="display: none; text-align: center;">
          <!-- ajax loader -->
        </div>
        <!-- mysql data will be load here -->
        <div id="content-dynamic"></div>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Chiudi</button>
      </div>

    </div>
  </div>
</div>

动态内容:

    <?php
    require_once '../../core/function.php';


if (isset($_REQUEST['id'])) {

    $id = intval($_REQUEST['id']);
    $query = "SELECT * FROM upload_contratti WHERE contratti_id = $id";
    $risultato = $conn->query($query);


?>

    <div class="table-responsive">
        <table id="record">
            <tbody>
                <?php  
                while ($riga_doc = $risultato->fetch_assoc()) {
                ?>

                    <tr>
                        <td style="width: 95%; padding-top:15px;">
                            <p><a href="././uploads/<?php echo $riga_doc["file"]; ?>" title="Scarica documento" alt="Scarica documento" download><?php echo $riga_doc["file"]; ?></a></p>
                        </td>
                        <td style="width: 20%;">
                            <a onclick="return confirm('Sei sicuro di volere eliminare questo elemento?');" id="deleteFile" data-id="<?php echo $riga_doc["id"]; ?>" title="Cancella"><i class="fas fa-trash-alt"></i></a>
                        </td>
                    </tr>


                <?php  
                }
                ?>
            </tbody>
        </table>
    </div>

<?php    
}
?>

感谢您的帮助

0 个答案:

没有答案