How do I define a variable in javascript with echo function, from the external php file?
We have theconfigfile.php, thejsfile.js an
There are a couple of ways you can go about doing this.
You can configure your webserver to process files with extension .js with PHP and just inject your PHP there. Of course this means you need a way to actually calculate your variable there, and this would slow down serving your regular javascript content.
You can simply output the PHP variable to a Javascript variable within a element like this
And then access this path variable in your AJAX. Most would probably use the second approach.