vineld Posted July 28, 2009 Share Posted July 28, 2009 Sometimes your Javascript code will need values generated by PHP right from the start. Usually I just print these values directly into the Javascript code since it's the quickest solution. What do the rest of you do, and more importantly, why? I am currently trying to ease the workload for a few sites with high traffic and try to compress js code where it's possible but then I can of course not have any php code there. Perhaps it would be a good idea to store these key values in a hidden form? After all, that is a more flexible solution. Quote Link to comment https://forums.phpfreaks.com/topic/167721-php-javascript-interaction-best-practice/ Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 Depending on the situation, there's no harm in doing that. The only thing that really does though is anchor js to a specific space in a script though. Can't easily move that around, sort of thing (moreso from script to script vs. within script, but even then). Using ajax is a bit more flexible. You can have a script dedicated to handing out values for variables and that frees you up to do whatever on the rest of your page, without having to work around the javascript. It also allows for multiple pages to draw from that single value controller script. Quote Link to comment https://forums.phpfreaks.com/topic/167721-php-javascript-interaction-best-practice/#findComment-884482 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.