我想从我的HTML文件访问JSON文件,我使用jQuery: $.getJSON("en.json", function(data) { console.log(data.age); });
JSON访问不工作
这似乎并没有工作,虽然。我使用Xampp来托管我的本地服务器,并且在本地存储时我读了JSON不起作用的地方。这可能是一个与此有关的问题吗?
谢谢
HTML代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
alert();
$.getJSON("en.json", function(data) {
console.log(data.age);
});
</script>
</head>
<body>
<div class="test">
Hi
</div>
</body>
</html>
JSON文件:
{
"add-school" : "Add School",
"age" : "Age",
"age-months" : "Age (in months)",
"age-years" : "Age (in years)",
"all-classes" : "All Classes",
"audio": "Audiometry",
"bmi" : "BMI",
"bp" : "BP"
}
在控制台中的任何错误看到的console.log(data.age)的结果? – Rayon
不,控制台中没有错误。 – BillyBob
什么是'console.log(data);' – Rayon