Passing Parameters and Handling PHP Errors
The previous exercise with PHP ignores two very common aspects of writing PHP scripts:
You usually need to send parameters to your server-side (PHP) script.
Now that the client side is quite well protected, you should implement some error‑handling technique on the server side as well.
You can send parameters to the PHP script using either GET
or POST
. Handling PHP errors is done with a PHP-specific technique. In the following exercise, you will pass parameters to a PHP script, and implement an error-handling mechanism that you will test by supplying bogus values. The application will look as shown in Figure 3.3.
This page will make an asynchronous call to a server, asking the server to divide two numbers for you. The server, when everything works well, will return the result as an XML structure that looks like this:
<?xml version=”1.0”?> <response>1.5</response>
In the case of a PHP error, instead of generating an XML string, the server...