I'm having trouble accessing an array created in php, to use in a javascript block. I know about
<?php echo json_encode($myArray); ?>
but I'm not getting any results out of it.
I have a 'index.html' file where I try to access the array through javascript. The html page exists out of a drop down menu. When the user chooses an item in that drop down menu, the chosen item is used as an argument to retrieve data from a database.
The 'ajax.js' file contains the code to execute the 'retrieve.php' file which constructs the array ('$myArray') from database content. So the array is retrieved through an ajax call.
Can I 'echo' to the javascript code from my php file:
echo 'dataArray = ' . json_encode($data_array) . ';';
and use that javascript variable? In other words, how can I execute my javascript code using that new 'dataArray' variable?
To get the bigger picture: I'm trying to use that array for use in a 'Google Chart', for which I need to use javascript to display the chart. I can query all data and put it in a php array, but I'm not succeeding in transfering it properly to my html page with javascript and reload the chart.
Edit: I use an ajax call to no to reload the entire page.