84 Part I: Core Ideas
conforming or coming close and the others not doing so. Figure 3-3 shows the results of
testing the common browsers at this edition’s writing; the complete results can be found at
http://ajaxref.com/ch3/requestexplorerresults.php.
Very likely, this situation is going to change as browser vendors start shoring up
the details and inconsistencies when developers start really exercising XHRs. Rather
than rely on results at one point in time, run the script at http://ajaxref.com/ch3/
requestexplorerscript.html yourself. By doing so, you help keep the chart automatically
updated until these details are worked out by the browser vendors. You may also find it
useful to use a browser HTTP debugging tool or run the Request Explorer at http://ajaxref
.com/ch3/requestexplorer.php to experiment with header values.
Other HT TP Requests
While most of time, GET and POST will be used in Ajax communication, there is a richer set
of HTTP methods that can be used. For security reasons, many of these may be disabled on
your server. You may also find that some methods are not supported in your browser, but
the first request method, HEAD, should be available in just about any case.
Head Requests
The HTTP HEAD method is used to check resources. When making a HEAD request, only
the headers are returned. This may be useful to check for the existence of a file, the file’s, or
to see if it has been recently updated before committing to fetch or use the resource.
Syntactically, there isn’t much to do differently versus previous examples except setting the
method differently, as shown here:
var url = "http://ajaxref.com/ch3/headrequest.html";
var xhr = createXHR();
if (xhr)
{
xhr.open("HEAD", url, true);
xhr.onreadystatechange = function(){handleResponse(xhr);};
xhr.send(null);
}
Authorization Delta-Base If-Unmodified-Since
Content-Base Depth Max-Forwards
Content-Location Destination MIME-Version
Content-MD5 ETag Overwrite
Content-Range From Proxy-Authorization
Content-Type If-Modified-Since SOAPAction
Content-Version If-Range Timeout
TABLE 3-6 setRequestHeader Values That Should Replace Existing Values