Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualHodgman

Posted 24 May 2013 - 09:25 AM

Your PHP code is running on the webserver whenever a user requests a page. Your Javascript code is running in the client's browser.

If you use document.write('PHP code here');, then all that will happen is that PHP code will appear on the clients screen.

In order to actually execute some PHP code on the server, the javascript code has to make a request to the webserver. You can either do this by loading a whole new page (as if the user clicked a link), or by using AJAX etc to load a new page in the background and extract information from it.

 

For the other direction, yes, the PHP code is typically outputting a HTML document, so you can echo a < script> tag with JS code in it, which will be executed by the client's browser when it loads the document.


#2Hodgman

Posted 24 May 2013 - 09:25 AM

Your PHP code is running on the webserver whenever a user requests a page. Your Javascript code is running in the client's browser.

If you use document.write('PHP code here');, then all that will happen is that PHP code will appear on the clients screen.

In order to actually execute some PHP code on the server, the javascript code has to make a request to the webserver. You can either do this by loading a whole new page (as if the user clicked a link), or by using AJAX etc to load a new page in the background and extract information from it.

 

For the other direction, yes, the PHP code is typically outputting a HTML document, so you can echo a < script> tag with JS code in it.


#1Hodgman

Posted 24 May 2013 - 09:19 AM

Your PHP code is running on the webserver whenever a user requests a page. Your Javascript code is running in the client's browser.

If you use document.write('PHP code here');, then all that will happen is that PHP code will appear on the clients screen.

In order to actually execute some PHP code on the server, the javascript code has to make a request to the webserver. You can either do this by loading a whole new page (as if the user clicked a link), or by using AJAX etc to load a new page in the background and extract information from it.


PARTNERS