Home » Php » trouble setting javascript variablet to output of php

trouble setting javascript variablet to output of php

Posted by: admin June 30, 2018 Leave a comment

Questions:

I’m trying to set a javascript variable to the output of a php script but the JS variables continues to evaluate to the literal output of the PHP snippet.

Even when I do something as simple as this in my .js file:

var list = "<?php echo 'foo'?>";

the JS variable comes out as:

"<?php echo 'foo'?>"

When I try removing the quotes, I get parsing errors.

I’ve seen several examples like the above on various sites, though, so I seems like this should work.

Answers: