javascript files with php code |
Hi guys, I'd like to ask for some generic information, if possible.
I usually try to put all my javascript stuff in a single file, and not keep them inside <skript> tags in my views, so it would be a little bit cleaner and tided up. However there might be some cases where I have ti embed some PHP code inside my javascript, for instance: PHP Code: <script type="text/javascript"> So in this case I'm just leaving these scripts in my views. I was wondering whether there's a more efficient way to do this, or another better way to organize all javascripts. Would you recommend another way, or in that case, or keep going this way ?
(10-02-2015, 09:02 AM)Lykos22 Wrote: Hi guys, I'd like to ask for some generic information, if possible. You can use global variables in JS . Example: Code: <script type="text/javascript">
10-02-2015, 08:14 PM
(This post was last modified: 10-02-2015, 08:17 PM by freddy. Edit Reason: make code )
yeah me too
I love too use my js file with single file js not mixing them in php, based on experience i have done like this in view Code: <script type="text/javascript"> then in my js i use this Code: url : product,
There are a few different ways to handle this - each have their pros and cons. It depends on preference and your specific requirements really.
This is a great post to refer to for information on each: http://stackoverflow.com/questions/23740...javascript I generally do what others have suggested. I have a single <script> element in my <head> which contains all variables I need echoed into JS, which I can then reference anywhere in my other JS files. I use this mostly for language lines, but it has other uses too.
So basically, you do something like this:
Code: <head> Am I right ? but what you do in cases like this, where you need to loop to set dynamically some js data ? See this example: PHP Code: 'columns': [ |
Welcome Guest, Not a member yet? Register Sign In |