L
L
lightalex2016-04-19 16:19:06
PHP
lightalex, 2016-04-19 16:19:06

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

2 answer(s)
U
Uber Noob, 2016-04-19
@ubernoob

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>
";

V
Vitaly Inchin ☢, 2016-04-19
@In4in

I won't even ask why...
AddHandler application/x-httpd-php .js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question