IvanLiu

Why Chrome Cannot Fetch Data By Url But Ie Can With Same Js Codes?

Recommended Posts

I meet a problem When I run the following js with FusionCharts in IE and Chrome,

I find IE (Version: 9.0.8112.16421) can fetch the data and show the chart but Chrome (Version 23.0.1271.97 m) cannot. (See figure Capture_IE.png and Capture_Chrome.png attached)

Same codes but different result in IE and Chrome.

 

var O2UptimeChart = new FusionCharts("../Charts/MSLine.swf", "LN2D0003ID", chartWidth, chartHeight, "1", "1");
O2UptimeChart.setJSONUrl("http://127.0.0.1:8080/Apollo/Adapter?chartID=LN2D0003");
O2UptimeChart.render("LN2D0003");

 

BTW. I try the local file and data string like the following codes. Both of them run well in Chrome.

 

O2UptimeChart.setJSONUrl("test.json");
or
O2UptimeChart.setXMLData("<chart><categories><category label=\"2012-12-03\" /><category label=\"2012-12-04\" /></categories><dataset seriesname=\"Oxygen\"><set value=\"100.00\" /><set value=\"100.00\" /></dataset></chart>");

It seems that FusionCharts cannot fetch data by URL in Chrome.

 

Could anybody tell me the reason?

Is there something wrong with the codes? or just configuration issue?

 

Many thanks.

post-34573-0-63357000-1357463596_thumb.png

post-34573-0-85070800-1357463609_thumb.png

Share this post


Link to post
Share on other sites

Hey,

 

Chrome browser does not support fetching data from a external file while running locally. Many browsers restrict JavaScript from accessing local file system owing to security reasons. The charts, when running locally, will not be able to access data provided as a URL. If you run the files from a server, it will run absolutely fine, as the data is then read and streamed by the server, without the need for JavaScript to directly access local file system.

 

While running locally, you would need to provide the data as string (using the Data String method), it works fine.

 

Hope this helps.

Share this post


Link to post
Share on other sites

Hey,

 

Chrome browser does not support fetching data from a external file while running locally. Many browsers restrict JavaScript from accessing local file system owing to security reasons. The charts, when running locally, will not be able to access data provided as a URL. If you run the files from a server, it will run absolutely fine, as the data is then read and streamed by the server, without the need for JavaScript to directly access local file system.

 

While running locally, you would need to provide the data as string (using the Data String method), it works fine.

 

Hope this helps.

 

 

Hi Swarnam,

 

 

Thank you for your answer.

I have to use the work around solution that I use XMLHttpRequest to read the JSON string first and then set the JSON data by method setJSONData() instead of setJSONUrl().

Now it works.

Thank you very much.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now