Jump to content

passing php variable to external javascript file


Neomech

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.