我在一個名為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條經驗 獲得超8個贊
僅在渲染表格后將初始化代碼放入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 關注
- 189 瀏覽
添加回答
舉報
0/150
提交
取消