␡
- Initializing an AJAX Application
- Sending a GET Request
- Sending a POST Request
- Sending a Synchronous Request
- Receiving Multiple Data from the Server
- Aborting an HTTP Request
- Retrieving HTTP Headers
- Receiving XML from the Server
- Using JSON for Data (De)Serialization
- Creating a Waiting Screen
- Solving the Bookmark Problem
- Solving the Back Button Problem
- Using XSLT
- Using an XML Library
- Using the Yahoo! Web Service
This chapter is from the book
Retrieving HTTP Headers
var headers = XMLHttp.getAllResponseHeaders();
The method getAllResponseHeaders() (see preceding code) returns all HTTP headers in the HTTP response, whereas the getResponseHeader() method returns just one specific header. The following code shows how to get information about the type of web server used:
Retrieving an HTTP Response Header (responseheader.html)
<script language="JavaScript" type="text/javascript" src="xmlhttp.js"></script> <script language="JavaScript" type="text/javascript"> var XMLHttp = getXMLHttp(); XMLHttp.open("GET", "phrasebook.txt"); XMLHttp.onreadystatechange = handlerFunction; XMLHttp.send(null); function handlerFunction() { if (XMLHttp.readyState == 4) { var servertype = XMLHttp.getResponseHeader("Server"); window.alert("Web server used: " + servertype); } } </script>
Note that not all servers send this header; some also put fake data in it to make server profiling harder.