Answer the question
In order to leave comments, you need to log in
How to execute php in js file?
Hello!
There was a need to execute a php script in a js file
Tried to do it using htaccess: AddType application/x-httpd-php .js
Php is not executed
If you replace js with html and run php in html, then everything works
Question, what's the problem? What are other solutions?
Answer the question
In order to leave comments, you need to log in
To begin with, it would be nice to understand what exactly php inside JS should do, what information to process?
You do not need to execute php in JS to prepare the data and pass it to JS with a regular echo, or use AJAX, which is most likely.
echo "
<script type=\"text/javascript\">
alert('Привет мир!');
</script>
";
echo "
<script type=\"text/javascript\">
alert('Hello World!');
</script>
";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question