Access php variable from external js file
First in your test.php file
$phpVar = 'from php';
echo "<script type="text/javascript">var jsVar = " $phpVar ";</script>";
echo "<script type="text/javascript" src="external.js"></script>";
Then use it in .js file
alert( jsVar );
Written by teknonono
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#