问题描述
只是想问一下。我想显示从 JSON 链接检索的数据列表。一切正常,直到我在每行数据添加一个查看按钮。此按钮将显示所选数据的详细信息。现在,我想添加 jscookie 以将基于所选行的 id 带到 viewDetails.html。但我不确定代码是否真实。你们可以检查一下吗?
var badgeid = '10010079';
$.getJSON('https://huhu.haha.com/hihi/huhu.asmx/ot_displayTask?badgeid=' + badgeid + '&reportStatus=&status=yes',function(data) {
$.each(data.otReportList,function(key,data) {
// console.log(key,data);
let current_datetime = new Date(data["report_date"])
let formatted_date = current_datetime.getDate() + "-" + (current_datetime.getMonth() + 1) + "-" + current_datetime.getFullYear()
var text = `<tr>
<td>${data["report_id"]}</td>
<td>${data["task_name"]}</td>
<td>${formatted_date}</td>
<td>
<form method="POST" action="viewDetails.html">
setCookie('reportid',data["report_id"],0.125),setCookie("viewid","yes",0.125);
<button type="submit" name="reportid">View</button>
</form>
</td>
</tr>`
$("#mypanel").append(text);
})
});
table,td,th {
border: 1px solid black;
}
table {
width: 100%;
border-collapse: collapse;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript - read JSON from URL</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="jscookie.js"></script>
</head>
<body>
<div>
<table id="mypanel">
<tr>
<th>Report ID</th>
<th>Task Name</th>
<th>Report</th>
<th>Action</th>
</tr>
</table>
</div>
</body>
</html>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)