为什么Json文件内容没有显示在html页面中?

时间:2013-06-19 11:54:11

标签: javascript json

我是javascript的新手,我想用javascript显示json文件的内容。我的问题是html页面无法显示Json文件的内容,它是空白的!!我知道我正确地抓它。我在我的本地驱动器上有这个Json文件,名称为data.json。我也更改了文件的地址,但它不起作用。

Coul你告诉我原因是什么? 谢谢,

我把代码放在这里

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>

<script>

    $(function() {


   var people = [];

   $.getJSON("home/Documents/data.json", function(data) {
       $.each(data.person, function(i, f) {
          var tblRow = "<tr>" + "<td>" + f.firstName + "</td>" +
           "<td>" + f.lastName + "</td>" + "<td>" + f.job + "</td>" + "<td>" + f.roll + "</td>" + "</tr>"
           $(tblRow).appendTo("#userdata tbody");
     });

   });

});
</script>
</head>

<body>

<div class="wrapper">
<div class="profile">
   <table id= "userdata" border="2">
  <thead>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email Address</th>
            <th>City</th>
        </thead>
      <tbody>

       </tbody>
   </table>

</div>
</div>

</body>
</html>

1 个答案:

答案 0 :(得分:3)

  

我在本地驱动器上有这个Json文件

不要尝试在本地磁盘上执行Ajax,否则会遇到浏览器安全限制。运行Web服务器并通过HTTP执行。

您应该通过在浏览器的开发人员工具中查看JavaScript错误控制台来了解这一点。