Because you're making
an asynchronous call, we need to register a callback event handler that the
XMLHttpRequest object will invoke when its readyState value
changes. Remember that a change to the readyState value generates a
readystatechange event. We register the callback event handler
using the onreadystatechange property.
xmlHttpReq.onreadystatechange=processRequest;
Next, we need to send the request using the send() method. Because this
request uses the HTTP GET method, the send() method may be invoked
without an argument or null argument.
xmlHttpReq.send(null);
1.6 Processing an Ajax Request
In this example, because the HTTP method is GET, the receiving servlet on
the server invokes a doGet() method, which retrieves the catalogId
parameter value specified in the URL, and checks its validity against a
database. The servlet needs to construct a response to be sent to the client.
1.6 Processing an Ajax Request 9
This example returns XML, so it sets the HTTP content type of the
response to text/xml and the Cache-Control header to no-cache.
Setting the cache-control header prevents the browser from simply
reloading the page from the cache.
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
...
...
response.setContentType(???text/xml???);
response.setHeader(???Cache-Control???, ???nocache???);
}
The response from the server is an XML DOM object.
Pages:
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37