Saturday, January 27, 2007

Chap 3 Cont'd

We begin with the coffee maker HTML code given to us. Also, since the JavaScript is pretty similar for each application, we are creating a separate JavaScript file called ajax.js (which relates to common applications) and coffee.js (for those that are specific to the coffee maker application). It's similar to separating HTML code with CSS.

The code that links the JavaScript file to the HTML and to replace inside the HTML is on page 154.


The next objectives are writing the JavaScript for orderCoffee(), getSize(), getBeverage(), sendRequest().

Also, there is a line of code to reset the form when an order has been placed so the next person that wants to order doesn't see the last order. It is: document.forms[0].reset().

The book has also included code for the coffeemaker.php file to interact with the server.

After having the the files ready, the serveDrink function is used to take the response from the server and figure out who placed the order, and which coffee maker was used to brew the drink. It is also used to set the status of the maker to idle and to alert the person that the coffee is ready.

The JavaScript substring() function is used to take a response string and breaking it up. It looks like this: var newString = myString.substring(startIndex, endIndex);

The last part of the chapter is dedicated to testing and finding that there's a need to create two request objects.

0 Comments:

Post a Comment

<< Home