刷新表内容。 jquery ajax

时间:2016-01-25 09:29:23

标签: php jquery ajax

我正在使用上一个问题的解决方案在删除行后刷新我的表格。 它工作,并很好地刷新我的表。但风格和其他链接的js不起作用。 前

before refresh

after refresh

//的index.php

    <div id="tableContainer">    
    <?php
        include('table.php');
    ?>
</div>

//的jquery / AJAX

   function deleteUser(id,thisObj){
           $.ajax({
             url: 'insert.php',
            type: 'POST',
             data: {'delAdmin':id}, // An object with the key 'submit' and    value 'true;
             success: function (result) {

            $("#tableContainer").html(result);

           }
       }); 
      }

// insert.php

 /*Delete  admin */ 
if(isset($_POST['delAdmin'])){
 $idval=$_POST['delAdmin'];
 $query="delete from admins where id=$idval";
 $result=mysqli_query($dbCnn,$query) or die("خطا!");

}     包括( 'table.php');

// table.php

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta charset="utf-8" />
   <!-- jquery ui -->
    <link rel="stylesheet" href="js/ui/jquery-ui.min.css"/>
    <script src="js/ui/jquery-ui.min.js"></script>
    <!--activejs-->
    <script src="js/activejs.js"></script>
   <!--include font-awesome -->
    <link rel="stylesheet" href="../fonts/awesome/css/font-    awesome.min.css"/>
     <!-- table paging and sorter -->
    <script type='text/javascript'    src='js/sortpager/dist/js/slimtable.min.js'></script>
     <link rel='stylesheet' href='js/sortpager/css/slimtable.css'/>
</head>

 <body>

 <table id="usersListTable" style=" border:1px solid #00CCFF!important;"    class="">
        <thead>
  <tr>
          <th>ردیف</th>
          <th>نام کاربری</th>
          <th>کلمه عبور</th>
          <th>رایانامه</th>
          <th>سطح</th>
          <th>فعال</th>
          <th>آخرین ورود</th>
          <th class="thBgNone"></th>
          <th class="thBgNone"></th>
        </tr>
</thead>
      <tbody id="tb">

      </tbody>
 <?php
            include("db_inc.php");
             $usersQry="select * from admins";
             $usersQryResult=mysqli_query($dbCnn,$usersQry);
              $c=1;
               while($user=mysqli_fetch_array($usersQryResult)){
               echo"
                  <tr>
                      <td>$c<span class='userId' style='display:none'>$user[id]</span></td>
                       <td>$user[user]</td>
                       <td>$user[pass]</td>
                       <td>$user[email]</td>
                       <td>$user[level]</td>
                       <td>$user[status]</td>
                       <td>$user[lastlogin]</td>
                       <td><i onclick=\"editUser($user[id],this)\" class='fa   fa-pencil-square-o' title='ویرایش اطلاعات کاربر'></i></td>
                    <td><i onclick=\"deleteUser($user[id],this)\" class='fa fa-trash-o deletUser' title='حذف کاربر' ></i></td>                    
                </tr>
            ";
            $c++;
           }
        ?>
   </table>
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

我可以看到你正在为jQuery使用SlimTable插件,它从现有的表数据创建可排序和可分页的表。在Ajax更新之后,您必须重新应用/重新启动SlimTable以重新格式化您的内容。请查看文档@ https://github.com/McFizh/slimtable

$("#usersListTable").slimtable({
    tableData: data
});