【问题标题】:Loading data from external json file with javascript or jquery使用 javascript 或 jquery 从外部 json 文件加载数据
【发布时间】:2013-05-21 17:30:22
【问题描述】:

我正在研究动态地将外部 json 文件中的数据用于我的 javascript。 我一定误解了如何调用文件,因为目前我什至无法访问数据...... 所以我的 html 调用了 js 文件。并且js文件使用这种方法调用json:

$(function() {
    function stockTimeline(){
        $.getJSON('json/corse_timeline/corse_timeline.json', function(donnees) {
            $('#wrap').html('<p>' + donnees.timeline.date[4].endDate + '</p><p>' + donnees.timeline.date[9].startDate + '</p><p>' + donnees.timeline.headline + '</p><p>' + donnees.timeline.date[30].headline + '</p><p>');
            console.log("this console.log IS NOT working");
        });
        console.log("this console.log IS working");
    }
    stockTimeline(); 
});

我从阅读过的几个教程中直接采用了这种方法。 如何测试我的 json 文件是否已损坏? 是因为我需要将它上传到服务器上才能使用吗?

【问题讨论】:

  • 控制台是否显示任何 javascript 错误?

标签: javascript jquery ajax json load


【解决方案1】:

您可以通过将 JSON 文件粘贴到 JSON Lint 来验证它。

【讨论】:

  • 我确实有很多解析错误!感谢您的链接,我现在正在纠正它;)
  • 方便的东西。有时您只需要新鲜的眼球,即使它们是机器的眼球。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-16
相关资源
最近更新 更多