为了账号安全,请及时绑定邮箱和手机立即绑定

数据表不适用于ajax加载的表

数据表不适用于ajax加载的表

PHP
青春有我 2023-12-15 14:58:34
我在一个名为values.php的文件中有一个表,我通过ajax从index.php调用这个文件,在索引中我有数据表脚本,我在索引中编写的示例表可以工作,但是通过ajax加载的同一个表没有 39;不工作。有什么问题吗?基本项目代码function call_table() {    var xhttp = new XMLHttpRequest();    xhttp.onreadystatechange = function() {        if (this.readyState == 4 && this.status == 200) {            document.getElementById("content").innerHTML = this.responseText;        }    };    xhttp.open("GET", "values.php", true);    xhttp.send();}call_table();PHP 值.php$data='    <div class="table-responsive">        <table id="sorting-table" class="table mb-0">            <thead>                <tr>                    <th>Order ID</th>                    <th>Customer Name</th>                    <th>Country</th>                    <th>Ship Date</th>                    <th><span style="width:100px;">Status</span></th>                    <th>Order Total</th>                    <th>Actions</th>                </tr>            </thead>            <tbody>                <tr>                    <td><span class="text-primary">054-01-FR</span></td>                    <td>Lori Baker</td>                    <td>US</td>                    <td>10/21/2017</td>                    <td><span style="width:100px;"><span class="badge-text badge-text-small info">Paid</span></span></td>                    <td>$139.45</td>                    <td class="td-actions">                        <a href="#"><i class="la la-edit edit"></i></a>                        <a href="#"><i class="la la-close delete"></i></a>                    </td>                </tr>                <tr>echo $data;
查看完整描述

1 回答

?
慕仙森

TA贡献1827条经验 获得超7个赞

仅在渲染表格后将初始化代码放入ajax代码中


function call_table() {

    var xhttp = new XMLHttpRequest();

    xhttp.onreadystatechange = function() {

        if (this.readyState == 4 && this.status == 200) {

            document.getElementById("content").innerHTML = this.responseText;

            $('#sorting-table').DataTable();        //here

        }

    };

    xhttp.open("GET", "values.php", true);

    xhttp.send();

}

call_table()

;


查看完整回答
反对 回复 2023-12-15
  • 1 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信