javascript - Using PHP in .JS file? -
so i'm trying use php in .js file, here's have far.
.htaccess (any *.api.js processed php)
<filesmatch "^.*?api.*?$"> sethandler php54-script </filesmatch>
map.api.js
<?php header("content-type: application/javascript"); //my php here ?> //my javascript here
.php files include
<script type="text/javascript" src="map.api.js"></script>
for reason isn't working, , after research can't find solution.
in chrome developer tools error, uncaught syntaxerror: unexpected token <
- pretty self explanatory, isn't expecting <?php
@ top of map.api.js
file.
anyone else here tried using php in .js file before? if there better solution i'd know can't find on google.
create file php extension , include in website javascript.
map.api.js
<?php header("content-type: application/javascript"); //my php here ?> //my javascript here
in html file:
<script type="text/javascript" src="map.api.php"></script>
if wan't hide php extension, can work mod_rewrite (apache):
rewriteengine on rewriterule ^map.api.js$ map.api.php
Comments
Post a Comment