What's the best way to pass a PHP variable to Javascript?

Posted by Gregory Bolkenstijn on Stack Overflow See other posts from Stack Overflow or by Gregory Bolkenstijn
Published on 2010-05-04T14:15:49Z Indexed on 2010/05/04 14:18 UTC
Read the original article Hit count: 242

Filed under:
|
|

I currently echo certain variables in hidden input fields and read them out with Javascript whenever I need them.

Me and a colleague are now thinking of generating an extra Javascript file with PHP which only contains all variables for Javascript. This way the variables already exist and there is no extra code in the HTML.

What are good ways to pass variables from PHP to Javascript? And how does our solution sound?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about php