Wednesday, January 16, 2008

XMLHttpRequest Properties

onreadystatechange
– Event handler that fires at each state change
– You implement your own function that handles this
readyState – current status of request
– 0 = uninitialized
– 1 = loading
– 2 = loaded
– 3 = interactive (some data has been returned)
• This is broken in IE right now
– 4 = complete
status
– HTTP Status returned from server: 200 = OK
responseText
– String version of data returned from server
responseXML
– XML DOM document of data returned
statusText
– Status text returned from server

Methods available in XMLHttpRequest Object

open(“method”, “URL”)
open(“method”, “URL”, async, username, password)
– Assigns destination URL, method, etc.
send(content)
– Sends request including postable string or DOM object data
abort()
– Terminates current request
getAllResponseHeaders()
– Returns headers (labels + values) as a string
getResponseHeader(“header”)
– Returns value of a given header
setRequestHeader(“label”,”value”)
– Sets Request Headers before sending

why is AJAX so hot—NOW?

• Demand for richer applications is growing
– Broadband means we can—and want to—do more
• It has a name
– Think LAMP—helped solidify the thoughts/techniques in people’s
minds
• Recent Google applications have sparked people’s imagination
– Google gmail, Google suggests, Google Maps
• People are thinking of building APPLICATIONS…not just sites
• The Tipping Point
– All of this has made rich internet apps reach its tipping point—
where adoption spreads rapidly and dramatically