简体   繁体   English

PHP的配置文件到外部JS文件

[英]php Config file to external js file

please help me on how to implement this 请帮助我如何实施
How can i pass/access a config varible from my Config.php to an external Php'd JS file 如何将Config.php中的配置变量传递/访问到外部Php'd JS文件

in my Config.php 在我的Config.php中

define('LIBS', 'http://localhost/libs/');  

I'm doing this in my external js file 我正在我的外部js文件中执行此操作

alert(<?php echo json_encode('LIBS');)  

my other option would be, re-initialize a the php config variables, something like this 我的另一个选择是,重新初始化一个php config变量,像这样

<script type="text/javascript">  
var jsLIBS= <?php echo json_encode('LIBS'); ?>
</script> 

within my main php file and set it as global variables 在我的主要PHP文件中,并将其设置为全局变量

thank you 谢谢

why just not: 为什么不呢?

<script type="text/javascript">  
var jsLIBS= '<?php echo LIBS; ?>';
</script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM