【问题标题】:Amcharts - Dataloader plugin not loading chart when php json outputting file is in include folderAmcharts - 当 php json 输出文件位于包含文件夹中时,Dataloader 插件不加载图表
【发布时间】:2017-10-26 15:15:24
【问题描述】:

我正在使用 Amcharts 创建可旋转并变成水平条形图的柱形图。我正在使用 Amcharts 的 dataLoader 插件连接到连接到 mysql 并检索数据的 php 文件,并且 php 文件将数据输出为 JSON

我面临的问题是,如果 php 文件与包含 html 的文件位于同一文件夹中,则图表会正确加载

,
  "dataLoader": {
    "url": "data.php"
  },

但如果我将 php 文件放在包含文件夹中,图表不会加载,并且会出现空白屏幕。

,
  "dataLoader": {
    "url": "http://MyWebsite.com/include/data.php"
  },

我检查了根目录和包含文件夹中的 php json 文件,两者都正确输出了有效的 JSON

我不想使用 Jquery,而且我是 javascript 新手。请告诉我做错了什么。

更新 - 此加载错误时断时续。这是浏览器控制台中出现的错误 - Failed to load http://MyWebsite.com/include/data.php: No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://www.MyWebsite.com is therefore not allowed access

【问题讨论】:

  • 您的浏览器控制台有错误吗?
  • 没有。但我会尝试检查 1-2 天是否有任何错误
  • Failed to load http://MyWebsite.com/include/data.php: No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://www.MyWebsite.com is therefore not allowed access @xorspark 这是我在浏览器控制台中遇到的错误。
  • 也许你应该尝试"/include/data.php" 避开网址。
  • 查看此链接:stackoverflow.com/questions/1653308/…。当您访问不同的地址时,您会遇到此问题。

标签: javascript php json amcharts


【解决方案1】:

由于浏览器的安全性,尝试从不同地址加载内容可能会导致跨域错误,如下所述:Access-Control-Allow-Origin Multiple Origin Domains?。就像您提到的那样,同一网站的http://http://www 之间的区别导致它打开和关闭错误。

考虑到调用的其实是同一个地址,最好的办法就是把http://MyWebsite.com/include/data.php改成include/data.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 2015-09-23
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多