you’re on your way 4
99
ajax requests
Next we need to tell the browser what to do when it gets a response from the server. Remember,
the browser will run the function we tell it about every time the ready state changes.
Giving instructions to the browser
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
var url = “lookupCustomer.php?phone=” + escape(phone);
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
Here’s the name of the function
that the browser should run
whenever the ready state of the
request object changes.
Be sure you set the
onreadystatechange property before
calling send(), so the browser knows
what to do when it gets a response.
Now that you’ve got the request URL gured out, you can initialize a connection using
the request object’s open() method. You should remember how the open() method
works from Chapter 1. Below is the line of JavaScript that initializes a connection, with
each parameter you give to open() on a separate line. In each blank, write in what the
parameter for that line tells the request object to do.
______________________________________________
______________________________________________
______________________________________________
request.open(
“GET”,
url,
true
);