Jump to content

PHP / Javascript interaction - best practice?


vineld

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.