javascript - 如何在ajax调用中附加来自rest服务的json数据
问题描述
当我试图在 ajax 调用中附加来自休息服务的数据时。只有最后一个值被附加到表中。
function getReporteeList() {
$.ajax({
url:'http://localhost:8088/JirasTrackingApp/reporter/Reportees/ReporteeList/'+ $("#ManagerId").val(),
type:'GET',
dataType: 'json',
success: function(result){
var content = '';
$.each(result,function(key,value){
content += '<tr>';
content = '<td>'+value.Name+'</td>';
content = '<td>'+value.UserId+'</td>';
content += '<td>'+value.count+'</td>';
content += '</tr>';
});
$('#employee_table').append(content);
}
});
}
以这种格式返回的 json 数据:
0: {UserId: "at1234", count: 0, Name: "Amreen Taj"}
1: {UserId: "AR1234", count: 0, Name: "Anagha R"}
2: {UserId: "MS1234", count: 4, Name: "Madhusudan S"}
但我得到的输出是:
Name UserName Count
MS1234 4
这是我的 html 表:
<table id = "employee_table">
<tr>
<th>Name</th>
<th>UserId</th>
<th>Count</th>
</tr>
</table>
请让我知道我哪里出错了
解决方案
排队
content += '<tr>';
content = '<td>'+value.Name+'</td>';
content = '<td>'+value.UserId+'</td>';
content += '<td>'+value.count+'</td>';
content += '</tr>';
你有时有+=,有时有=;
它应该会爆炸,但浏览器会自动修复无效的 HTML 结构。
推荐阅读
- r - 数据框中散布的分类值的累积计数,独立于每个 id
- php - 无法安装composer PHP版本错误
- jmeter - 解析异常 - jMeter json 后处理器;在提取json响应的最后一个元素时
- keras - Keras 损失函数的季节性
- c# - asp.net 核心中的 csp-report 端点
- plotly.js - hoverinfo 在 plotly 中无法使用 hovertemplate
- java - 如何在 Java 中修复 mediawiki-api 上的“readapidenied”错误
- java - java - 如何在带有java StAX条件的结束标签之前创建新标签?
- sas - 在 SAS 中创建数据集,n+1 是做什么的?
- ios - 如何在 iOS 应用中显示 iframe