【发布时间】:2017-06-23 01:55:49
【问题描述】:
如何使用 javascript 和 php 调用本地 JSON 文件?... 我试过这个,但它有一个错误。我希望你能帮我解决这个问题
<html>
<head>
<title></title>
<script src="jquery.min.js"></script>
<script src="jput-2.js"></script>
<script src="jput-2.prod.js"></script>
<script src="jput.min.js"></script>
<script>
$(document).ready(function(){
var json = JSON.parse('ticket.json');
//while running this code the template will be appended in your div with json data
$("#tbody").jPut({
jsonData:json,
//ajax_url:"youfile.json", if you want to call from a json file
name:"tbody_template",
});
});
</script>
</head>
<body>
<div jput="tbody_template">
<tr>
<td>{{ticket:id}}</td>
<td>{{score}}</td>
</tr>
</div>
<table>
<tbody id="tbody">
</tbody>
</table>
</body>
</html>
控制台显示错误
这是我的 json 代码:
{
"user": {
"id": 21821290968,
"url": "https://51talk.zendesk.com/api/v2/users/21821290968.json",
"name": "Rovi Roy Cruz",
"email": "rovi.cruz@51talk.com",
"created_at": "2017-04-26T09:55:33Z",
"updated_at": "2017-06-23T02:10:22Z",
"time_zone": "Beijing",
"phone": null,
"shared_phone_number": null,
"photo": null,
"locale_id": 1,
"locale": "en-US",
"organization_id": null,
"role": "admin",
"verified": true,
"external_id": null,
"tags": [],
"alias": "",
"active": true,
"shared": false,
"shared_agent": false,
"last_login_at": "2017-06-23T02:10:22Z",
"two_factor_auth_enabled": null,
"signature": "",
"details": "",
"notes": "",
"custom_role_id": null,
"moderator": true,
"ticket_restriction": null,
"only_private_comments": false,
"restricted_agent": false,
"suspended": false,
"chat_only": false,
"default_group_id": 42443967,
"user_fields": {
"system::embeddable_last_seen": "2017-06-21T00:00:00+00:00"
}
}
}
【问题讨论】:
标签: javascript php jquery html json