Including PHP variables in an external JS file?

前端 未结 6 443
清酒与你
清酒与你 2020-12-06 03:15

I have a few lines of jQuery in my web application. This code is inline at the moment because it accepts a couple of PHP variables.



        
6条回答
  •  Happy的楠姐
    2020-12-06 03:59

    You cannot put it into an external .js file if you still want to include PHP variables. But you can put the code into a separate PHP file that generates valid Javascript output (including content-type in the header set to "text/javascript"!).

    In your first PHP file you can refer to the second PHP file generating the Javascript code with

    
    

提交回复
热议问题