Yes, it's been asked a lot. No, I still can't get it to work after days of searching online. (also: yes, I'm still pretty new to php and much of a copy/paste coder). I have an array in PHP called EP. I shuffle EP. I then need the shuffled values of EP passed onto a javascript array.
I checked out all the answers here Convert php array to Javascript but no succes: Spudley's answer uses php and javascript in one file, whereas I'm using seperate files (index.php, data.php, main.js). If I use Eric's answer netbeans tells me 'expected operant but found..'
the array is located in data.php:
$EP = array(30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220);
shuffle($EP);
I need this shuffled array (in the shuffled order) in my main.js, so I can display it in a graph with jqplot. I used this, but then the whole js file basically stops working
var arrayFromPHP = "<?php echo json_encode($EP); ?>";
alert( $.toJSON(arrayFromPHP) );
and I tried the following, but the alert says 'undefined'
$.getJSON("data.php",function($EP){
alert( $.toJSON($EP) );
});
Could someone point out my mistakes?