Section 2.37. Test driving the Break Neck app


2.37. Test driving the Break Neck app

Make sure you've added all the JavaScript we've talked about into pizza.html. Then, open up the page in your web browser, and enter in a phone number. It looks like everything is working! The server answers your request, and fills in the form with your address from the customer database.

Enter in a phone number. (The version of lookupCustomer.php you downloaded from the Head First Labs site will accept any phone number you enter.)

test drive As soon as you leave the phone number field, the page should automatically fill in the customer's address and order.

Remember, none of this involves a customer having to click a button or submit the pizza form.

The customer's address, which the Break Neck PHP script looked up, got filled in.

The customer can start working on their order while the server is getting their address.

So we're ready to start accepting orders again, right?

Wait just a second...

I was typing in my address before updatePage() got a response and filled it in. That seems sort of confusing... and annoying! Can't we fix that?

2.37.1. Order matters in asynchronous apps

When you're writing synchronous applications, you can usually put your fields on a form in whatever order you like. But for synchronous applications like Break Neck, you're going to have to think a little harder about how your form should look.

In the Break Neck order form, you probably don't want customers to start entering their address, and then have your callback function overwrite that with the address from the server. Instead, let's re-order the form, so customers go from the phone number field to the order field. That way, customers can start entering their pizza order while their address is being looked up.

Go ahead and flip these two fields in your pizza.html file.

Now customers will enter their order after typing in their phone number. By the time they're done, their address will have already appeared.

And what about that Windows problem from back in Chapter 1? Don't we need to fix that so Break Neck runs on Macs and PCs?

2.37.2. What's going on in Windows?

Internet Explorer is a pretty smart browser, and tries to do lots of things to help make your browsing a better and faster experience. For instance, it will cache a lot of your images, so if you visit a page with lots of graphics, and then come back later, you'll see the graphics come up really quickly.

IE tries to do something similar with URLs. If you make a request to a server-side program, IE keeps track of the URL you requested. Then, if you make a request to the same URLwithout any different dataIE figures you're going to get the same response. So, instead of re-sending the request, it just gives you the result from the first time you made the request.

Since we first saw this problem in the Boards 'R' Us app, let's start by fixing that app on Windows. Then, we can take what we learned and fix up Break Neck Pizza, too.

The Opera browser does the same thing that IE does in this situation: it caches URLs.

brain power

Why would Internet Explorer's and Opera's caching of requests cause a problem in the Boards 'R' Us application? Will this also create trouble for customers using the Break Neck pizza order form? And what should we do to try and fix this problem?





Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net