Is it possible to JSON this php array via json_encode?
Because this php array is called $data
and when i do..
var myJson =
As @Allendar said you can't embed PHP inside a JS file. You could, however, add a function in your JS file to load the JSON data, and then embed that data in a script tag in your PHP file.
example.js:
var loadJsonFromPHP = function(json) {
console.log(json);
}
example.php:
Edit: this is assuming you only need to get the data into JS once at page load, in which case you can skip making AJAX requests.