0

I have a php page that queries a mysql db and return a .json file.

I want this page to be called within a coffeescript page, but I don't understand the syntax to accomplish this.

I have seen here that in plain js you can do:

var json = eval(<? echo $json ?>);   

but this is not a valid coffeescript syntax... is there a coffeescript alternative to eval() I can use? Or is there any alternative way I can go?

1
  • As pointed out in this question stackoverflow.com/questions/14010133/… you can use JSON.parse(json) to grab the json string and convert it into a json object. Commented Feb 16, 2017 at 15:36

1 Answer 1

0

Yo do not need eval to parse a string of JSON into an object. It should be enough to use JSON.parse.

json = JSON.parse(<?php echo $json; ?>)
Sign up to request clarification or add additional context in comments.

4 Comments

thanks, but the problem is stating this from coffeescript and as far as I got, you cannot use "var"... am I wrong?
@user299791 I am not too familiar with coffeescript, but as long as you parse the content of your JSON file it should be accessible like any other object in coffeescript afterwards.
I need to call this php page every time something changes in the UI and the UI is managed with coffeescript... that's why I have this precise question...
just do data = JSON.parse(json) other than the absence of "var" there isn't much difference.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.