AJAX - The Complete Reference

(avery) #1

PART IV


Appendix B: HTTP 1.1 Reference 607


NNOT EOTE In the case of reading a file from the local drive, the browser relies instead on a file extension
such as .html to determine the contents of a file. Obviously, saving a resulting page from a
server-side program with its native extension (for example, .php) may cause some problems if you
attempt to open it locally, as you will not be executing code but simply viewing the result.

As discussed in previous chapters, particularly Chapters 3, 4 and 6, correct MIME usage
in Ajax applications is quite important. You need to be very careful in the case of browsers
like Internet Explorer, which may attempt to sniff response content and override any
specified MIME type. In the capture shown in Figure B-1, we see Internet Explorer
interpreting a text/plain response as HTML just because it peeks into the response and
sees some tags in the data stream.
We also recall that an Ajax application-consuming XML needs to see responses with
appropriate Content-Type values like text/xml; otherwise, the XMLHttpRequest object
at the heart of Ajax will not populate its responseXML property. As discussed in Chapter 3,
some browsers support an overrideMimeType() method for the XHR object in order to
deal with incorrect MIME type values in a Content-Type header.
This brief discussion serves only as a reminder of the lessons of Chapters 3 through 6,
which taught that putting in the appropriate effort to understand MIME is quite important.
In some sense, one can think of the core Web protocols—HTML, HTTP, and MIME—like the
world-famous three tenors. People often only remember the first two, but it truly takes three
to make everything work!

FIGURE B-1 Internet Explorer sniffi ng content
Free download pdf