JavaScript stops working after enabling embedded PHP in Apache

  • Thread starter Bernhard Georg Enders
  • Start date
B

Bernhard Georg Enders

After issuing the command (apache httpd.conf file)
AddType application/x-httpd-php .php .htm .html
any attempt to include javascript code
<script src="file.js" type="text/javascript"></script>
into htm (or html) file fails. How can I successfully config Apache2 to
work with
embedded PHP and javascript at same time?

TIA,

Bernhard Enders.
 
G

Grant Wagner

Bernhard said:
After issuing the command (apache httpd.conf file)
AddType application/x-httpd-php .php .htm .html
any attempt to include javascript code
<script src="file.js" type="text/javascript"></script>
into htm (or html) file fails. How can I successfully config Apache2 to
work with
embedded PHP and javascript at same time?

You shouldn't be having a problem, you aren't modifying either the mime
type (text/javascript) nor the extension (.js) with that directive.

I would suggest you do 3 things:

1) search httpd.conf for other instances of ".js".
2) check mime.types for other instances of "text/javascript" or ".js", the
only one you might have is "application/x-javascript js" and that
should not affect your ability to send script as <script
type="text/javascript">
3) ensure your JavaScript loads correctly _without_ PHP, and after you've
enabled PHP, ensure that the HTML source you are viewing is what you
_think_ you're sending. For example, if you had PHP that looked like: echo
"script type=\"text/javascript\" src=\"" . someVariable . "></script>"; Do
you notice the closing quote on the SRC attribute is missing? You would if
you loaded that page into your browser and did a View -> Source.

But quite frankly, most browsers aren't that picky. For example, our
corporate Web server sends .js files as application/x-javascript, and I've
never had a problem with <script type="text/javascript">. I would suspect
your problem is more with some change you made to the .js file, or some
interaction between quotation marks delimiting PHP text and internal
quotation marks within the generated HTML. That's why it's important to
View -> Source.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top