how to include a php config file in javescript file ?

Discussion in 'HTML & Website Design' started by nohypo, Apr 23, 2010.

  1. #1
    --------------------------------------------------------------------------------

    such as in js file j.js
    I wanna evalue js variable to a php Constant varialble defined in config.php
    so I need include the config.php
    how to do this?
     
    nohypo, Apr 23, 2010 IP
  2. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think I know what your TRYING to do but please explain in English so I can be sure what you wan to do...

    Explain by leaving out: "wanna", "evalue"(which is not a word), "variable"(which you spelled wrong), "constant" and "defined"
    These are the thing I can not make out because they are causing a loop to nothing.

    Just tell us what it is you really want...
     
    Blasingame, Apr 24, 2010 IP
  3. canadianguy_001

    canadianguy_001 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you need to get your web server to parse javascript files as php... or... just make your js file a php file...

    <script type="text/javascript" src="myjavascript.php">
    PHP:
    and then inside myjavascript.php:
    
    var jsVar = "Here is a regular javascript variable";
    var phpVar = "<?php echo "Here is a js variable passed from php"; ?>";
    alert(jsVar+phpVar);
    
    PHP:
     
    canadianguy_001, Apr 24, 2010 IP
  4. nohypo

    nohypo Active Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    Digital Goods:
    2
    #4
    sorry ,
    such as I have a php file config.php
    <?php
    $Host_php="http://www.a.com";
    $Port_php="8899";
    ?>

    and have a javascript file run.js
    <?php
    include "config.php"
    var host_js = "<?php echo $Host_php?>";

    ?>


    but the host_js get an empty value instead of the value of $Host_php
    can you help ?
     
    nohypo, Apr 24, 2010 IP