I want to call a javascript function from my PHP code. I have achieved this by using:
echo '<script type="text/javascript"> drawChart($id); </script>';
This works fine, but I want to get data from my PHP code, which I did using the following:
var t_array = ?php echo json_encode($t_array); ?>;
(Yes, I know there's a > missing.) I think the PHP closing tag is interfering with the rest of the code. So now my question: How can I get PHP data without using the PHP tags?
Thanks in advance
$t_array?drawChart($id);will be exactly that, because that string is in single-quotes - so it won't be passed as a variable. And there's a<missing in front of what should be<?php. And that's exactly how you get it, there's no need for AJAX unless you need it dynamically without reloading the website of the PHP values changes.var t_array = JSON.parse(<?php echo json_encode($t_array);?>)should work fine. Use ParseJson function.