So PHP is executed server-side. But is it possible for PHP to be run after the page is loaded?
To illustrate, if I had a value (stored in a file, lets say) that chan
I think you need to get one of those diagrams that show how basic HTTP and the web server works. It will make more sense to you, than explained in plain words here.
In the simplest possible case, the result of you typing some address and getting a web page with its contents can be summed up, due to a result of process in request/response
relationship between your browser and a web server located somewhere in the world.
In a less simpler way, think of it like this. basically, if a page is during a refresh phase, (meaning you clicked something and are waiting for a data to comeback) then, that means it is getting/loading the response from the web server. If the web server does not have PHP installed as a module, then the only thing it is waiting/loading (in many cases) is plain HTML content.
On the other hand, if we assume you have a file called index.php
in your webserver, and have PHP is installed, in this case the web server will send everything that appears in-between to the PHP interpreter, first, then wait for it until PHP does its magic and send back to the server only the result.
So, in the above case, the webserver (ex: Apache, Nginx) does not care what is inside the opening and closing tags, and sends the entire code to the PHP interpreter, and PHP would compute that script according the way it understands it and sends only the computed result back to the server, as plain HTML. In this case the number 2
.
AJAX (Asynchronous JavaScript and XML) is a technique used Javascript, to help you send requests and receive the response without having to load the page. This is usually done by using the browsers XHR object. So, there is no mystery in this whole shebang.
The above can be summed up simply in the following steps.
index.php
back to browser if tag