Neomech Posted September 19, 2009 Share Posted September 19, 2009 Hi there. I have a feeling this is a simple problem, but I can’t figure it out. I'm using CodeIgniter and making use of the MVC concept. One of the things that I do is create dynamic javascript in some of my views. I know how to pass php variables to the view from my controller and use them to create the javascript I want on the page. What I am trying to do is pass the variables to an external javascript file. I like to keep all my javascript code in external files (and that seems to be widely encouraged). I know how to use a dynamic external .js file using the .php extension, and I can run php code in the external javascript file just fine. What I DON’T know how to do is to pass php variables from my controller that will somehow make their way into the external javascript files. I realize I could call the external javascript files with a querystring that I could set dynamically, but what if I want to pass in an array, or a simplexml object or something. I tried using global variables and didn’t seem to get anywhere with that. Does anyone know how to do what I’m attempting? Is it even possible? Quote Link to comment https://forums.phpfreaks.com/topic/174816-passing-php-variable-to-external-javascript-file/ Share on other sites More sharing options...
RussellReal Posted September 19, 2009 Share Posted September 19, 2009 if u can use php in ur javascript files.. than just use sessions and echo the sessions where you want the variables to be placed in your js Quote Link to comment https://forums.phpfreaks.com/topic/174816-passing-php-variable-to-external-javascript-file/#findComment-921364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.