Use PHP code in external Javascript file

前端 未结 5 405
甜味超标
甜味超标 2020-12-01 05:54

I am just wondering if it\'s possible to use external JS file that contains PHP code.

my external JS

$(document).ready(function(){

    $(\'#update\         


        
5条回答
  •  攒了一身酷
    2020-12-01 06:21

    I believe it is possible, but as Brian mentioned you have to let the preprocessor know it needs to process it. You can either tell it to use php to handle .js files (Not recommended) or simply use a .php file for your javascript, then use:

    
    

    This should be okay because the mime type is still javascript so it will be interpreted that way. I've never actually tried this, so it is a guess, but I believe it should work.

提交回复
热议问题