I still think you are confused about locality and execution timeline.
- The browser requests a page from your server. Maybe because the user clicked on a link, or entered the page address in the browser's navigation bar.
- Your server receives the request, and passes the request to your PHP script that handles the page
1. The PHP script generates an HTML page and gives it to the server to send to the browser
2. The server sends the generated output to the browser
3. THE PHP SCRIPT IS DONE! Finished. No more. It's job is completed.
4. The browser loads the page, renders it on the screen, and runs the Javascript (if any) in the page.
5. The PHP code doesn't run in the browser. The Javascript code doesn't run on your server. They don't even run at the same time. Once the browser runs the Javascript the execution of the PHP script is history.
Some Javascript code can send some data to your server, using Ajax. It can send it to the same - or different - PHP script on your server. But it is a NEW execution of the script in either case.
Jake showed you how to use ONE script to perform TWO functions. If it is a page request, it sends the page. If it is an Ajax request, it uses the data received to update the database. But it is just a trick for using the SAME script to perform both functions. It would be better to just write two PHP scripts.
If your PHP script sends some data back from the Ajax request, then your Javascript code can use the data sent back in any way it might like. For example, to update some part of the page. Or not.
Your PHP script CANNOT directly change anything in the page in response to the Ajax request. The PHP script runs on your server, and has no access to Javascript variables or the page content. All it can do is send back some data in the response, and then it is up to your Javascript code to do something with that data.