【发布时间】:2017-12-21 10:03:58
【问题描述】:
您好,假设我有以下 ajax 调用:
jQuery.ajax({
type: "GET",
url: "https://myurl.com",
success: function(data)
{
console.log(data);
}
});
这会产生以下 json 数据(在我的控制台中)
{
"meta": {
"last_updated": "2017-07-06"
},
"results": [
{
"term": "DRUG INEFFECTIVE",
"count": 1569
},
{
"term": "NAUSEA",
"count": 1374
},
{
"term": "FATIGUE",
"count": 1371
}
]
}
如何在我的 HTML 页面中填充 div,并使用以下格式的数据:
term: x
count: xx
term: x
count: xx
term: x
count: xx
我对“元”的东西不感兴趣,只对“结果”感兴趣
有人知道如何使用简单的循环来显示这些数据吗?
谢谢!
【问题讨论】:
-
在
success: function(data) { ... }“for循环”到data.results,然后使用jQuery填充目标div。