Question:
Execution order of Server Side and Client Side Code?
Stereotape
2012-05-11 07:16:18 UTC
I know server-side code executes on the server and client-side executes in the browser.

My question is, in what order do these events actually happen? A specific, step-by-step explanation of the web page life cycle would be great.

I ask because I want to know if you can embed PHP into a piece of JavaScript. The way I understand the web page life cycle:

1. The server executes ALL of the PHP code in a file.
2. The file generated from this execution is then sent to the client.
3. The client runs all JavaScript code.

If this is how it works, PHP should be embedded into Javascript no problem, because PHP comes first. However, it doesn't seem to work, so I'm thinking I have the life cycle wrong.
Three answers:
AnalProgrammer
2012-05-11 07:52:12 UTC
1. Request sent to server for web page.

2. Server receives request and locates the page

3. The page is scanned for any server side processing, PHP, CGI etc and executes it

4. The now extended page is sent back to client.

5. Client machine executes any html, CSS or Javascript it finds and displays the page based on browser rules.



PHP code can be placed anywhere in a page. Including imbedded in CSS or Javascript. There is only one pass of execution for both server side and client side so if something is not working then look at the source file to see what is wrong.



Have fun.
CramShark.com
2012-05-11 07:36:30 UTC
Your order is correct, but your explanation doesn't make sense.



After step 2, any php is just treated as text (rendered page based on the browser). The only code that can be ran after step 2 is client side code aka javascript, jquery. If you embed the php in javascript then it does no good, the browser doesn't know what php code is, the browser pretty much only knows javascript and html.



You need to either conditionally include javascript from your php or need another roundtrip to the server to execute the php.
anonymous
2016-10-01 08:21:35 UTC
A server-component application( eg : ASP.internet applications) will run on server and settlement with distant person via sending and getiing innovations via cyber web content. yet a shopper component(like JavaScript) runs on shopper's browser. and the server purely sends the appliance report to the shopper to run


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...