php - Is it possible to post values to external javascript file? -
hay,
i wondering if it's possible execute php code in external javascript file? example need read user language , such.
you can run php in js file if add php handler text/javscript.
<files *.js> addtype application/x-httpd-php .js </files> be sure have javascript file identify with...
header('content-type: text/javascript'); but...
as can imagine, every javascript file running through php isn't idea.
so i , use, this...
<script type="text/javascript"> var lang = '<?php echo $lang; ?>'; </script> <script type="text/javascript" src="/js/common.js"></script> then inside of common.js, can access lang variable.
Comments
Post a Comment