To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side languagelanguages are, and how they work.
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user.
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
So you can easily see that server side languagelanguages handle HTTP requestrequests and process itthem, and, as @deceze said, PHP is executed on the server and outputs some HTML, and maybe JavaScript code, which is sent as a response to the client, where the HTML is interpreted and the JavaScript is executed.
While atOn the other hand, Client Side LanguageLanguages (like JavaScript) resides onreside in browser and runs atrun in the browser,. Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified, so for security stuff we must not rely on JavaScript.
So when you make a HTTP request on server than The, the server first reads the PHP file carefully to see if there are any tasks that need to be executed, and sendsends a response to the client side and again. Again, as @deceze said, Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do so by reloading the page and sendsending a HTTP request
- youYou can make an AJAX call with JavaScript and- this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
So you can easily see that server side language handle HTTP request and process it and as @deceze saidPHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.
While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what client side and server side languages are, and how they work.
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user.
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
So you can easily see that server side languages handle HTTP requests and process them, and, as @deceze said, PHP is executed on the server and outputs some HTML, and maybe JavaScript code, which is sent as a response to the client, where the HTML is interpreted and JavaScript is executed.
On the other hand, Client Side Languages (like JavaScript) reside in browser and run in the browser. Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified, so for security stuff we must not rely on JavaScript.
So when you make a HTTP request on server, the server first reads the PHP file carefully to see if there are any tasks that need to be executed, and sends a response to the client side. Again, as @deceze said, Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do so by reloading the page and sending a HTTP request
- You can make an AJAX call with JavaScript - this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. theyThey reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
soSo you can easily see that server side language handle HTTP request andand process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.
whileWhile at the other hand Client Side Language (like JavaScript) Resideresides on browser and runruns at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not relayrely on JavaScript.
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to callcall PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. they reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
so you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed
while at the other hand Client Side Language (like JavaScript) Reside on browser and run at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not relay on JavaScript
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.
While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
- 4k
- 2
- 18
- 30
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. heythey reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
so you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed
while at the other hand Client Side Language (like JavaScript) Reside on browser and run at the browser , Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not relay on JavaScript
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. hey reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
so you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed
while at the other hand Client Side Language (like JavaScript) Reside on browser and run at the browser , Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not relay on JavaScript
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read:
To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work
Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. they reside on the server, these programs never have their source code exposed to the user
Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svg image attr
so you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed
while at the other hand Client Side Language (like JavaScript) Reside on browser and run at the browser , Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.
JavaScript is visible to the user and can be easily modified so for security stuff we must not relay on JavaScript
So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.
Graphical representation
So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.
- You can do by reloading page and send HTTP request
- you can make AJAX call with JavaScript and this does not require reloading page
Good Read: