1
我想填充在其上的一個模式繪製一個DataTable我的數據,我搜索了很多環節和我遇到一個有趣的話題來了..填充在數據表中的數據不能正常工作
我有一個按鈕將觸發該函數以獲取從servlet數據..
<button class="w3-btn w3-black w3-round-xxlarge w3-hover-green" id="viewButton" onClick="loadDoc(this.id)">View</button>
我的AJAX代碼..
<script>
function loadDoc(id) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
openModal(this.responseText);
}
};
xhttp.open("GET", "/ETEEAP/ViewApplication?id=" + id, true);
xhttp.send();
}
function openModal(id){
document.getElementById('id01').style.display='block';
loadTable(id);
}
</script>
我能打開模式,但它返回「請求未知」的錯誤 http://datatables.net/tn/4爲錯誤的詳細信息...
這是我的模態代碼..
<div id="id01" class="w3-modal">
<div class="w3-modal-content w3-animate-top w3-card-8" style="margin-top:20px;">
<header class="w3-container w3-teal">
<span onclick="document.getElementById('id01').style.display='none';"
class="w3-closebtn">×</span>
<h2>Program Details</h2>
</header>
<div class="w3-container w3-light-grey" style="margin-bottom: 50px;">
<div class="w3-container w3-padding-8 w3-opacity w3-white w3-round-xlarge w3-border w3-hover-border-black"
style="margin: 10px 10px 10px 10px;">
<table id="myTable1" class="display">
<thead>
<tr>
<th>SUBJECT</th>
<th>COURSE</th>
<th>UNITS</th>
<th>SEMESTER</th>
<th>YEAR LEVEL</th>
<th>STATUS</th>
</tr>
</thead>
<tfoot>
<tr>
<th>SUBJECT</th>
<th>COURSE</th>
<th>UNITS</th>
<th>SEMESTER</th>
<th>YEAR LEVEL</th>
<th>STATUS</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
<script>
function loadTable(id){
alert(id);
$('#myTable1').DataTable({
aaData : id,
aoColumns : [
{mDataProp : "SUBJECT"},
{mDataProp : "COURSE"},
{mDataProp : "UNITS"},
{mDataProp : "SEMESTER"},
{mDataProp : "YEAR LEVEL"},
{mDataProp : "STATUS"}
]
});
}
</script>
</div>
</div>
這是我從servlet得到的迴應..
[{"SUBJECT":"Programming I","UNITS":"3","SEMESTER":"First","COURSE":"BSCPE","YEAR LEVEL":"First","STATUS":"PENDING"}, {"SUBJECT":"Communication Arts I","UNITS":"2","SEMESTER":"First","COURSE":"BSCPE","YEAR LEVEL":"First","STATUS":"PENDING"}, {"SUBJECT":"Programming II","UNITS":"3","SEMESTER":"Second","COURSE":"BSCPE","YEAR LEVEL":"First","STATUS":"PENDING"}, {"SUBJECT":"COMORG","UNITS":"4","SEMESTER":"Second","COURSE":"BSCPE","YEAR LEVEL":"Second","STATUS":"PENDING"}]
當我運行這個程序時,它拋出上面的錯誤..但是當我分配和硬編碼指定的響應變量上它工作正常..如何它不工作?誰能幫助我..
你可以發佈'loadTable'函數嗎? –
它對模式代碼..:D –
你的servlet響應是字符串還是JSON對象? – CMedina