php tags in .js file

后端 未结 4 1703
名媛妹妹
名媛妹妹 2020-12-15 02:34

How do I enter a in a .js file. This is a jquery app, therefore the js file.

Thanks Jean

4条回答
  •  独厮守ぢ
    2020-12-15 03:01

    You regularly don't use PHP within your JavaScript files. Javascript is a client-side language which is interpreterred in your web browser. PHP is run on the web server.

    However, if you need to pass data from your PHP-code to your javascript document, you can do something like:

    $js = "";
    print $js;
    

    If you do this in your -part of your HTML-document, you will have access to myObject in other JS files you load after that.

    $your_data can be an array or any kind of object, string or integer. Look for PHP JSON around the interwebs.

提交回复
热议问题