简体   繁体   中英

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

in my Config.php

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

I'm doing this in my external js file

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

my other option would be, re-initialize a the php config variables, something like this

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

within my main php file and set it as global variables

thank you

why just not:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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