如何在ajax之后刷新表

时间:2018-01-21 10:51:19

标签: php jquery ajax codeigniter

我的问题是,我不需要刷新谁将刷新表格内容,我需要在客户端使用jQuery执行此操作。这可能吗?

我有一个表格,其中包含从数据库收到的信息。在这个表中我有一个按钮,按下它将发送AJAX请求功能,这将禁止评论。如果表的内容在成功完成AJAX响应(包含状态的所需行)后会发生变化,那将是完美的



<table class="table">
  <!-- Here is my table -->
  <?php foreach ($comments as $row) { ?>
  <tr>
    <td>
      <?php echo $row->Content; ?>
    </td>
    <td>                                            <!--------- /// --------->
      <?php if ($row->IsBanned == 0): ?>            <!--------- /// --------->
      <span class="label label-success ls">OK</span><!------ THIS  ROW ------>
      <?php else: ?>                                <!------ will  be  ------>
      <span class="label label-danger ls">Ban</span><!------ refreshed ------>
      <?php endif ?>                                <!--------- /// --------->
    </td>                                           <!--------- /// --------->
    <td style="text-align: right;">
      <div class="t_a_r" style="display: inline-flex;">
        <?php if ($row->IsBanned == 0): ?>
        <a class="btn btn-warning btn-xs ban" id="<?php echo $row->IdComment; ?>" role="button"><i class="margin-0 fa fa-ban"></i></a> <!-- on click this button to send ajax -->
        <?php endif ?>
      </div>
    </td>
  </tr>
  <?php } ?>
</table>
&#13;
&#13;
&#13;

并点击按钮$(&#34; .ban&#34;)我向codeigniter函数发送ajax请求。脚本:

&#13;
&#13;
$('.ban').click(function(event) {
      var id = $(this).attr('id');
    
      $.ajax({
        type: "POST",
        data: {
          id: id
        },
        cache: false,
        url: '<?php echo base_url(); ?>admin/banQuestion',
        success: function(msg) {
          //here code to refresh table content
          //for example table column which contains "Status"
        },
      });
    });
&#13;
&#13;
&#13;

0 个答案:

没有答案