0

这是与 HTML 文件位于同一目录中的 feature-table.JSON:

[
  {
    "band": "Weezer",
    "song": "El Scorcho"
  },
  {
    "band": "Chevelle",
    "song": "Family System"
  }
]

这是我的 HTML 文件:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.11.1.min.js">
<script type="text/javascript" src="jquery.dynatable.js"></script>
<script type="text/javascript">
$.getJSON("feature-table.JSON", function(data) {
    alert(data);
    $("#feature-table").dynatable({
        dataset: {
            records: data
        }
    });
});
</script>
</head>
<body>
<table id="feature-table">
  <thead>
    <th>band</th>
    <th>song</th>
  </thead>
  <tbody>
  </tbody>
</table>
</body>
</html>

警报会弹出正确的 JSON 数据,所以我知道它正在找到它。我已经尝试过:jQuery 的第 2 版,上传和使用 js 文件的 URL 以确保文件位于正确的位置,$.ajax 但是在读取Load remote JSON from Dynatable后的 $.getJSON以及其他各种东西。我没主意了。我在看什么?

4

2 回答 2

2

我发现我需要将我的 JavaScript 放入$(document).ready(function(){...}).

于 2014-06-16T22:56:18.563 回答
0

希望这可以帮助。

您是否还根据 JSON 数组的文档包含了元数据。

    {
      "records": [
        {
          "someAttribute": "I am record one",
          "someOtherAttribute": "Fetched by AJAX"
        },
        {
          "someAttribute": "I am record two",
          "someOtherAttribute": "Cuz it's awesome"
        },
        {
          "someAttribute": "I am record three",
          "someOtherAttribute": "Yup, still AJAX"
        }
      ],
      "queryRecordCount": 3,
      "totalRecordCount": 3
    }
于 2014-06-18T13:43:48.527 回答