I have a php file which needs to pass an array to an external javascript file. I'm trying to do it using AJAX
because it seems like the proper way to do so. I'm trying to do an echo json_encode($exif)
and then get it in the js but the json is printed on my current page. How can I achieve what I'm doing and what's the proper way to do it?
I'm trying to do the first solution of this answer How to pass variables and data from PHP to JavaScript? but I don't see how to integrate the php part so that it doesn't show up on my page.
Here is the php code. I need to pass the array while building my view. Therefore when I do the echo, the whole array is displayed on the page.
public function makeImagePage($image)
{
...
$this->parts["content"] .= "<p><u>Localisation:</u> </p>";
$this->parts["content"] .= '<div id ="map"></div>';
echo json_encode($exif);
$this->parts["content"] .= '<script type="text/javascript" src="js/map.js"></script>';
...
}