2 Replies - 4444 Views - Last Post: 06 April 2009 - 03:07 PM

#1 sharmistha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 04-November 08

Using php in js file

Post icon  Posted 06 April 2009 - 07:42 AM

Hello,
Can I put php coding in a .js file? I understand that php is server-side and js is client-side. I want to call a php function and add data to the .js file, dynamically ....
Is This A Good Question/Topic? 0
  • +

Replies To: Using php in js file

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Using php in js file

Posted 06 April 2009 - 07:53 AM

You can't put them in the same file, but if I understand what you are asking, it is indeed possible using an AJAX call.
This tutorial:
http://www.dreaminco...wtopic44808.htm
should get you started with making it work.
Was This Post Helpful? 0
  • +
  • -

#3 c0mrade  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 412
  • Joined: 16-November 07

Re: Using php in js file

Posted 06 April 2009 - 03:07 PM

Your server should have settings for what file extensions to parse for PHP, maybe if you add ".js" to the list you will get the desired result?

Remember, you can always include JS in your html files.

EDIT:
This is assuming of course that you want to use PHP to generate JS code. If you want to call JS from PHP, go with the above suggestion.

This post has been edited by c0mrade: 06 April 2009 - 03:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1