This line of code var $sTest = <?php echo $a = $_GET['ID']?> returns a “Uncaught reference error: .. is not defined.”
For this question, if we assume I am passing an ID of “ABC.” When I use the Developer Tools in Chrome and inspect the Resources, I can see that the $_GET has worked because it shows me the variable value. The error message in this case is “Uncaught reference error: ABC is not defined.”
I can’t work out how to assign the php variable to a script var. Help appreciated.
It’s because you have to quote your php script’s output:
will became
And in your Javascript enviroment the
somethingis not defined. If you want to preserve as much type information as you can, you should use json_encode on the php side like this: