Im a test.
In the code line of the example above we just need to replace the request line with:
.
onclick = "makeRequest (test.xml)">
.
Then in alertContents () we need to change the alert line (httpRequest.responseText); with:
var xmldoc = httpRequest.responseXML;
var root_node = xmldoc.getElementsByTagName (root) .item (0);
alert (root_node.firstChild.data);
responseXML retrieves our XMLDocument object and we will use DOM methods to access some of the data contained in the XML page.
Example source code can be downloaded at TGVT website, you can also run directly at http://goldenkey.edu.vn/ajax.
onreadystatechange
The event handler for an event arises every time a state changes.
readyState
Status: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete
responseText
Data as String returns from the server
responseXML
Document object compatible with DOM of data returned from the server
status
The numeric status code returned by the server, like 404 for "Not Found" or 200 for "OK"
statusText
The message String message comes with a status code.
Pham Cong Dinh
Golden Key Language Center
--------------------------------
References
1. Workshop document Effective Ajax 8/2005 (Jim Halberg and Rob Sanheim)
2. HTTP status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
3. DOM:http://www.w3.org/DOM/