1

Sorry sorry sorry for the basic question but I've been stuck on this for a while and I am not sure what is up.

So I have a php file and a json file. When I run the php file on the terminal

php myFile.php

the output is identical to my json file.

the output looks like this:

[{"word":"now","score":"16","sentence":" Now, at the least calcu- lation, 
this broken vase dates back two thousand five hundred years "}]

(the Json file also looks like the above)

When I pass in the json file to d3.json, I am able to see the visualization and all of it's data no-problem. But for some reason, when I replace the json file with the php file I am getting the error

Cannot read property 'length' of undefined
at Object.a [as extent]

so I am never getting or displaying the data. I've made sure that the php file is in the same directory, no typos etc. And I've checked the echo for any differences but there are none.

Thank you for your time!

my js looks like this:

//can replace myFile.php with json file and it works!
d3.json('myFile.php', 
function (error,myData) {
// a bunch of stuff})

Thank you!

Ore Arowobusoye
  • 147
  • 1
  • 7

1 Answers1

0

Convert your data to json using PHP's built in function json-encode

Then return the variable to d3.js.

  • You should also [send the right headers](https://stackoverflow.com/questions/4064444/returning-json-from-a-php-script/4064468#4064468) – thibautg May 24 '18 at 05:51
  • Do you have another message in the console (DevTools)? Is the php file correctly requested in the DevTools' Network tab? – thibautg May 24 '18 at 19:13
  • no other messages in the console, and yes the php file is in the network tab! – Ore Arowobusoye May 25 '18 at 02:27