3.29. A closer look at the request object
To figure out what's going on with Jim's order, let's take a closer look at each step of the test drive on the last two pages, and what our request object is actually doing.
Enter an order for Jim: he wants a large mocha. Then click "Order Coffee".
Request Object Remember, the request object is created by the static
JavaScript in ajax.js.
Make Jim a large mocha using the first coffee maker At this point,
the request object is used to send a request to the server-side
coffee maker.
coffeemaker.php
Jim's order starts brewing, using the first coffee maker.
Nothing changes for the request object during this step.
The server is still brewing Jim's coffee.
Request Object
coffeemaker.php The coffee maker is brewing Jim's large
mocha.
Now enter another order, for Bob. Bob wants a medium latte. Click "Order Coffee", and Bob's order should start brewing on the second coffee maker.
The same request object
is used to send the request for Bob's coffee order.
Request Object
Make Bob a medium latte using the second coffee maker The
same request object sends another request to the coffee maker for
Bob's order.
coffeemaker.php
Bob's order will finish normally, but Jim's order "disappears" forever.
A request object can be used to make multiple requests, but can
only keep track of one response from the server at a time.
The connection between the request object and Jim's order
was overwritten when Bob placed his order.
Request Object
Jim's order There's no request object set up to
indicate a callback to run or receive a server's response from the browser
when the server finishes with Jim's order.
Bob's order Bob's order is set
up normally. The request object will tell the browser what callback function to run,
and the callback can get the server's response from the request object.
 |