you’re on your way 4
187
asynchronous applications
s
e
n
d
(
)
o
p
e
n
(
)
s
e
t
R
e
q
u
e
s
t
H
e
a
d
e
r
s
(
)
Request Object
The same request object sends
another request to the coffee
maker for Bob’s order.
Make Bob a medium latte using
the second coffee maker
coffeemaker.php
3
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.
s
e
n
d
(
)
o
p
e
n
(
)
s
e
t
R
e
q
u
e
s
t
H
e
a
d
e
r
s
(
)
Request Object
But what about Jim’s order?
Do you see the problem? Jim’s order is still brewing, but now there’s
no request object attached to that request! The request for Bob’s order
overwrote the information in the request object related to Jim’s order:
Bob’s order
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
nishes with Jim’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.
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.
4
Bob’s order will
nish normally,
but Jim’s order ...