Amcharts - 当 php json 输出文件位于包含文件夹中时,Dataloader 插件不加载图表
Amcharts - Dataloader plugin not loading chart when php json outputting file is in include folder
我正在使用 Amcharts 创建可旋转并成为水平条形图的柱形图。我正在使用 Amcharts 的 dataLoader
插件连接到 php 文件,该文件连接到 mysql 并检索数据,php 文件输出数据为 JSON
我面临的问题是,如果 php 文件与包含 html 的文件位于同一文件夹中,图表会正确加载
,
"dataLoader": {
"url": "data.php"
},
但是,如果我将 php 文件放在包含文件夹中,则图表不会加载,并且会出现空白屏幕。
,
"dataLoader": {
"url": "http://MyWebsite.com/include/data.php"
},
我检查了根目录和 include 文件夹中的 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
由于浏览器的安全性,尝试从不同地址加载内容可能会导致跨源错误,如下所述:Access-Control-Allow-Origin Multiple Origin Domains?。正如您提到的,同一网站的 http://
和 http://www
之间的差异导致它打开和关闭错误。
考虑到调用实际上是针对同一个地址,最好的解决方案是将 http://MyWebsite.com/include/data.php
更改为 include/data.php
我正在使用 Amcharts 创建可旋转并成为水平条形图的柱形图。我正在使用 Amcharts 的 dataLoader
插件连接到 php 文件,该文件连接到 mysql 并检索数据,php 文件输出数据为 JSON
我面临的问题是,如果 php 文件与包含 html 的文件位于同一文件夹中,图表会正确加载
,
"dataLoader": {
"url": "data.php"
},
但是,如果我将 php 文件放在包含文件夹中,则图表不会加载,并且会出现空白屏幕。
,
"dataLoader": {
"url": "http://MyWebsite.com/include/data.php"
},
我检查了根目录和 include 文件夹中的 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
由于浏览器的安全性,尝试从不同地址加载内容可能会导致跨源错误,如下所述:Access-Control-Allow-Origin Multiple Origin Domains?。正如您提到的,同一网站的 http://
和 http://www
之间的差异导致它打开和关闭错误。
考虑到调用实际上是针对同一个地址,最好的解决方案是将 http://MyWebsite.com/include/data.php
更改为 include/data.php