Chapter 18: Scripted HTTP
This entry is a review of “Chapter 18: Scripted HTTP” from “JavaScript: The Definitive Guide”
This chapter discusses how scripted HTTP can be preformed in JavaScript. Below are my notes.
- Comet – Refers to a web architecture where the server asynchronously pushes updates to the client (Ajax is the reverse of this – the client asynchronously sends data to the server).
- The XMLHttpResponse object allows for these methods: GET, POST, DELETE, HEAD, OPTIONS, and PUT.
- XMLHttpRequest object automatically handles cookies, connection lifetime (though you can abort), *charset*, encoding negotiations, and the “Content-Length”, “Date”, “Referer”, and “User-Agent” headers.
- The XMLHttpRequest API is designed as if each method was writing to a network stream. Thus, you cannot set request headers before you call open. (the order of operations matter)
- The status code, response headers and response text are available upon a completed response from the XMLHttpRequest object.
- overrideMimeType – Method of XMLHttpRequest object that allows you to override the mime type returned by the server.
- XHR2 – New XMLHttpRequest specification that provides numerous improvements (CORS, file uploads, etc etc).
- Forms with key/value pairs and files, must be submitted using the “multipart/form-data” mime type. This kind of object can be constructed using a FormData object.
- For XHR2, you can monitor the progress of downloads/uploads with the progress API.
- JSONP allows for cross-origin communication, but has security risks.
- EventSource – This object can be used to implement Comet. In recent months its taken a backseat to WebSockets (which allow two-way communication and have their own protocol). However, Server Side Events happen over HTTP, are one way, and can generate custom events, so they have their place.
Leave a Comment