【发布时间】:2019-07-11 12:15:28
【问题描述】:
我正在尝试从我的 .json 文件(从服务器)中获取数据,然后将其显示在页面上。 JS的语法我不是很好,对不起。
我试图只显示文件中的一个参数,但我在屏幕上看不到任何内容。
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script>
$(function() {
$.getJSON("video.json", function(data)) {
$.each(data.NewsSources, function(i, f) {
var vid = f.Name;
$(vid).appendTo("#userdata");
});
});
});
</script>
</head>
<body>
<div id= "userdata">
<h1>This is a name</h1>
</div>
</body>
</html>
video.json
{
"NewsSources": [
{
"ID": 2004,
"Name": "365TV Brasil",
"Description": "",
"URL": "https://www.instagram.com/365scoresbra",
"Lang": 31,
"CountryID": 21,
"LogoUrl": "",
"ImgVer": 0
}
]
}
【问题讨论】:
-
用
$("#userdata").append(vid)代替$(vid).appendTo("#userdata")。