响应式数据表对ajax没有更多响应

时间:2017-06-01 13:27:24

标签: jquery ajax datatables responsive

我使用带有响应式扩展的jQuery DataTables并且它工作正常,但我需要保持查看的数据是最新的我想要使用Ajax每N秒更新一次数据。问题是当加载新数据时,我的表会失去其形状并且不再响应。我该如何解决这个问题?

以下是加载新数据前的外观:

enter image description here

以下是加载后的样子: enter image description here

1 个答案:

答案 0 :(得分:0)

这是更新我的DataTable的jquery函数:

function viewdata(){
  $.ajax({    
  url: 'susp.php', 
  success: function(data) { $('#hoona').html(data); }
        });
}

这里是页面susp.php:

<?php
include "classes.php";
$res= $db->query("select `crm`.`suspects`.`id` AS `id`,`crm`.`suspects`.`nom` AS `nom`,`crm`.`suspects`.`prenom` AS `prenom`,`crm`.`suspects`.`tel_per` AS `tel_per`,`crm`.`suspects`.`raison_sociale` AS `raison_sociale`,`crm`.`suspects`.`domaine` AS `domaine`,`crm`.`suspects`.`poste` AS `poste`,`crm`.`suspects`.`adresse` AS `adresse`,`crm`.`suspects`.`email` AS `email`,`crm`.`suspects`.`tel_pro` AS `tel_pro`,`crm`.`suspects`.`web_site` AS `web_site`,`crm`.`suspects`.`fax` AS `fax`,`crm`.`suspects`.`statut` AS `statut`,`crm`.`suspects`.`date_contact` AS `date_contact`,`crm`.`suspects`.`type_contact` AS `type_contact`,`crm`.`suspects`.`commentaire` AS `commentaire`,concat_ws(' ',`crm`.`users`.`nom`,convert(`crm`.`users`.`prenom` using utf8)) AS `nom_delegue` from (`crm`.`suspects` left join `crm`.`users` on((`crm`.`suspects`.`idd` = `crm`.`users`.`id`))) where ((`crm`.`suspects`.`statut` = 0) or (`crm`.`suspects`.`statut` = 1) or (`crm`.`suspects`.`statut` = 2))");
while($row = mysqli_fetch_array($res))  {
                                    echo "<tr>";
                                    echo "<td class=\"nostar\">" . $row['nom'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['prenom'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['poste'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['raison_sociale'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['domaine'] . "</td>";
                                    echo "<td class=\"nostar\">" . statut($row['statut']) . "</td>";
                                    echo "<td class=\"nostar\">" . $row['nom_delegue'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['date_contact'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['type_contact'] . "</td>";
                                    echo "<td class=\"star\">" . $row['commentaire'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['email'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['web_site'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['tel_pro'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['tel_per'] . "</td>";
                                    echo "<td class=\"star\">" . $row['adresse'] . "</td>";
                                    echo "<td class=\"nostar\">" . $row['fax'] . "</td>";
                                ?>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button type="button" class="btn btn-default edit-susp" id="<?php echo $row["id"]; ?>"><span class="glyphicon glyphicon-pencil"></span></button>
                                        <button type="button" class="btn btn-default prospetih" id="<?php echo $row["id"]; ?>">Passer comme Prospect</button>
                                        <button type="button" class="btn btn-default del-susp" id="<?php echo $row["id"]; ?>"><span class="glyphicon glyphicon-trash"></span></button>
                                    </div>
                                </td>
                                </tr>
                                <?php
                                  }
?> 

请注意,与我第一次复制/调整数据时获取数据的代码相同。 并注意#hoona是表格的tbody的id。 并感谢您的回答^ _ ^ @ Gyrocode.com