如何使用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>
并且那里有&#39;在控制台显示错误
这是我的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"
}
}
}
答案 0 :(得分:2)
检查以下代码对您有用:
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="jput.js"></script>
<script>
$(document).ready(function(){
$("#users").jPut({
ajax_url:"my.json", //if you want to call from a json file
name:"users",
});
});
</script>
<div jput="users">
<table border="1">
<td>Id: {{id}}</td>
<td>Id: {{email}}</td>
</table>
</div>
<div id="users"></div>