How to define a variable in JavaScript with PHP echo function?

前端 未结 7 1395
囚心锁ツ
囚心锁ツ 2020-12-18 13:33

How do I define a variable in javascript with echo function, from the external php file?

We have theconfigfile.php, thejsfile.js an

7条回答
  •  生来不讨喜
    2020-12-18 14:12

    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

    And then access this path variable in your AJAX. Most would probably use the second approach.

提交回复
热议问题