Javascript 如何在本地文件夹上调用json
如何使用javascript和php调用本地JSON文件?。。。 我试过这个,但有个错误。我希望你能在这方面帮助我Javascript 如何在本地文件夹上调用json,javascript,php,jquery,html,json,Javascript,Php,Jquery,Html,Json,如何使用javascript和php调用本地JSON文件?。。。 我试过这个,但有个错误。我希望你能在这方面帮助我 <html> <head> <title></title> <script src="jquery.min.js"></script> <script src="jput-2.js"></script> <script
<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>
检查以下代码,它将适用于您:
<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>
$(文档).ready(函数(){
$(“#用户”).jPut({
ajax_url:“my.json”,//如果要从json文件调用
名称:“用户”,
});
});
Id:{{Id}
Id:{{email}
hi@Harsh Patel,请在控制台中确认您收到了类似cross origin的错误。对吗?没有,在我的屏幕截图“未捕获的语法错误:位置1处JSON中的意外标记o”@ivor请检查我编辑的答案,它将适用于you@ivor检查我编辑的代码,它将有助于将json转换为html
<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>