我想在jquery中用jQuery文件打包json文件。什麼是我的錯,此代碼在jQuery閱讀json文件在javascript中
$(function() {
var new4 = [];
$.getJSON('new4.json', function(data) {
$.each(data.new4, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.FirstName + "</td>" +
"<td>" + f.LastName + "</td>" + "<td>" + f.EmailAddress + "</td>" + "<td>" + f.City + "</td>" + "</tr>"
$(tblRow).appendTo("#userdata tbody");
}
ss);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id="userdata" border="2">
<thead>
<th>FirstName</th>
<th>LastName</th>
<th>EmailAddress</th>
<th>City</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
我的JSON代碼
{
"person": [
{
"firstName": "Clark",
"lastName": "Kent",
"Email Address": "Reporter",
"City": 20
},
{
"firstName": "Bruce",
"lastName": "Wayne",
"Email Address": "Playboy",
"City": 30
},
{
"firstName": "Peter",
"lastName": "Parker",
"Email Address": "Photographer",
"City": 40
}
]
}
對於源,我下載一個jQuery文件fromwebsite到我的文件夾中。
我添加了這張照片,因爲源對於json非常重要,我想確定我的方法是創建一個html。
你這次得到什麼錯誤信息? –
其實一無所獲。 Html打開,但沒有數組或其中包含json文件。當我開始時,只顯示html文件,沒有json給出的信息。 –