简体   繁体   中英

How to access external javascript file from the php file

I need to access a javascript function which is in the separate file.

Here is what I am trying to do:

in the php file I have:

var session_lang= <?php echo $_SESSION['SESS_LANGUAGE'];?>;
    if (session_lang!='')
    {
        check_and_change(session_lang);
    }
});

and I have this check_and_change() function in that separate javascript file which is of course included.

One more thing. I am getting error that there is a unknown < sign, so probably my php variable can't be read. If someone can please check that too.

If the error line is the line with the session_lang variable, then you forgot the double qoutes (if the session_lang is a string).

var session_lang = "<?php echo $_SESSION['SESS_LANGUAGE'];?>";
    if (session_lang!='')
    {
        check_and_change(session_lang);
    }

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