我在一个名为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()
;
- 1 回答
- 0 关注
- 131 浏览
添加回答
举报
0/150
提交
取消