It likely sounds a bit like voodoo to you now, so perhaps a bit more detail is in order. For example, suppose you want to use a web page to display some data that resides on the server. Here’s a general look at the steps involved in that process:
- JavaScript determines the data that it needs from the server.
JavaScript has various ways it can do this, such as extracting the information from the URL, reading an item the user has selected from a list, or responding to a click from the user.
- JavaScript sends a request for that data to the server.
In most cases, JavaScript sends this request by calling a PHP script on the server.
- The PHP script receives the request and passes it along to MySQL.
The PHP script uses the information obtained from JavaScript to create an SQL command that MySQL can understand.
- MySQL uses the SQL command to extract the required information from the database and then return that data to the PHP script.
- The PHP script manipulates the returned MySQL data into a form that JavaScript can use.
JavaScript can’t read raw MySQL data, so one of PHP’s most important tasks is to convert that data into a format called JavaScript Object Notation (JSON, for short, and pronounced like the name Jason) that JavaScript is on friendly terms with.
- PHP sends the JSON data back to JavaScript.
- JavaScript displays the data on the web page.
One of the joys of JavaScript is that you get tremendous control over how you display the data to the user. Through existing HTML and CSS, and by manipulating these and other web page elements using JavaScript, you can show your data in the best possible light.