Re: Alter html variable contents

From: Date: Mon, 04 May 2015 10:30:30 +0000
Subject: Re: Alter html variable contents
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-324862@lists.php.net to get a copy of this message
On 4-5-2015 11:10, Alf C Stockton wrote:
I already have <div id="loadingNode"></div> in my HTML and both the HTML and PHP are in the same file and I want loadingnode to be populated with the message produced by PHP after user clicked appropriate link.
I don't think you understand when what happens in this case. So let's explain with a typical http request: 1. The user presses a button/link/types in an url 2. The browser sends a request for that page to the server 3. The server receives the request and looks up the file on the server 4. The file is a PHP file, and is executed on the server (this is where and when all your PHP code is ran) 5. The results (echo'd, printed, etc.) from your PHP file are gathered by the server and sent back to the browser as a response to the request 6. Your browser shows the result of the response (which is a full, new HTML page) to the user. These are all separate steps which follow one after the other. One has to finish before the next starts. None of these steps continues while another is being processed (roughly, there are a few exceptions, but these are not important here). As you can see, PHP is ran *before* the user even gets to see or click on a link. So changing HTML *after* the browser has received it *via PHP* is simply not possible (since PHP has long since finished by then). What you want is slightly confusing, since you don't explain exactly what you want. If you want display different content, simply echo/print different content. As long as this does not depend on someone pressing a button and having the change happen inside that page instantly, this is just fine. However if for example you want the user to press a link and instantly have the content of only that <div> change, then you need a client-side script, for example written in javascript (in contrast to PHP which is a server-side scripting language). I hope this helps you understand what happens during/after a request and that you are now able to decide what exactly you want. - Tul --- This email has been checked for viruses by Avast antivirus software. http://www.avast.com

« previous php.general (#324862) next »