【发布时间】:2017-10-31 21:56:13
【问题描述】:
我有这个响应输出(JSON 类型)--> 从控制器传递
[["Subash Nisam",test,"Medix Care","2017.03.02","9.30 am 到 10.30 am"],["Subash Nisam",test,"Medix Care","2017.03.02" ,"3.30 到 5.30"]]
我想使用 Javascript 将它附加到表 tbody 之后-->
<table class="table table-bordered table-hover" id="doctorresultTable">
<thead>
<tr>
<th>Doctor Name</th>
<th>Speciality</th>
<th>Hospital</th>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
我该怎么做?
这是我的 JS 代码:
function searchbyNameandDate(name, avadate) {
var ajaxConfig = {
type: "GET",
url: "searchbyNameandDate?name=" + name + "&date=" + avadate,
async: true,
dataType: "json"
};
$.ajax(ajaxConfig)
.done(function (response) {
for (var i = 0; i < response.length; i++) {
for (var j = 0; j < 4; j++) {
var html = "<tr> \
<td>" + response[i][j] + "</td> \
<td>" + response[i][j] + "</td>\
<td>" + response[i][j] + "</td> \
<td>" + response[i][j] + "</td> \
<td>" + response[i][j] + "</td> \
</tr>";
$("#doctorresultTable tbody").append(html);
}
}
})
.fail(function (xhr, status, errorMessage) {
alert("failed to load data");
console.log("XML HTTP REQUEST : " + xhr);
console.log("Status : " + status);
console.log("Error message : " + errorMessage);
});
}
}
【问题讨论】:
-
我可以看看你的代码吗?到目前为止你尝试了什么
-
我已经提交了我的js代码
标签: javascript html ajax html-table response