Mixing php and javascript -- under what conditions? -


under conditions can put php javascript code? ok? bad idea? surprised have not seen more.

for example, came across this..

$('#thumbnail').imgareaselect({aspectratio: '<?php echo $thumb_height/$thumb_width;?>', onselectchange:preview});  

..which in onpage script element. i'm not experienced, surprised had never seen mixed js/php before. can put php in .js files well? if set file extension .php, file parsed?

you can put php code *.js files need tell webserver execute php interpreter on *.js files. should in httpd.conf

<ifmodule php5_module>     addtype application/x-httpd-php .php .php5 .js      ... </ifmodule> 

a better solution rename *.js files *.js.php or *.php. browsers won't mind , php interpreter executed on those.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

delphi - How to convert bitmaps to video? -