简体   繁体   中英

getting json data with d3.json() from php not working

I am using Javascript d3.js library to draw some charts which are getting data from a MySQL database using php. I have used d3.json() to read from a php file which is 'echo'ing some JSON value. This works fine in my PC XAMPP server but not working on a 000webhost free server. Can someone please tell me what could be the problem? I am getting JSON data using The following way .

d3.json(d3/section1/section1.php, function(data) {...

the php file is echo ing the following json array:

[{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[88],"mark":[90],"info":"Network"},{"spark":[0.1,0.3,0.2,0.5,0.1,0.4,0.2,0.3,0.2,0.7,0.6,0.5],"mes":[87],"mark":[85],"info":"ERP"},{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[90],"mark":[100],"info":"Data Warehouse"},{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[95],"mark":[90],"info":"Web Site"},{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[98],"mark":[88],"info":"Email"},{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[90],"mark":[96],"info":"HR"},{"spark":[1,0.2,0.3,0.5,0.1,0.4,0.8,0.3,0.2,0.7,0.6,0.9],"mes":[100],"mark":[92],"info":"Problem Tracking"}]

URL不需要是字符串吗?

d3.json("d3/section1/section1.php", function(data) {...

The problem is solved. The online server was a free server which is embedding a javascript enclosed by html tags at the end of each page. That was creating problem calling the expected correct JSON string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM