Foundations of Ajax PDF
Foundations of Ajax PDF
The Plan
Where have we been? Where are we now? Where are we going?
Very rich applications Upgrades a pain (new hardware anyone?) Simplied maintenance, low barrier of entry Less functional apps, browser issues
We conditioned users with thick apps Then we took that all away Convinced our users to accept thin apps The browser pushed us towards plain vanilla Applets, Flash, XUL/XAML/XAMJ Fundamental Issue - Web is based on a synchronous request/response paradigm
What is Ajax?
Give me an A
Ajax is a catch-phrase - several technologies Asynchronous, JavaScript, XML, XHTML, CSS, DOM, XMLHttpRequest object More of a technique than a specic thing Communicate with XHR, manipulate the Document Object Model on the browser Dont repaint the entire page! We gain exibility
http://www.adaptivepath.com/publications/essays/archives/000385.php
Google Suggest
Google Maps
XHR Methods
Method
open(method, url [, asynch [, username [, password]]]) send(content)
Description
Sets the stage for the call - note asynch ag. Sends the request to the server.
abort()
getAllResponseHeaders()
Returns all the response headers for the HTTP request as key/value pairs. Returns the string value of the specied header.
getResponseHeader(header)
setRequestHeader(header, value)
XHR Properties
Property
onreadystatechange
Description
The event handler that res at every state change.
readyState
The state of the request: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete The response from the server as a string.
responseText
responseXML
status
statusText
Typical Interaction
Ajax Enabled Web Application 3 XHR 2 1 Event 6
function callback() { //do something }
4 Data store
Client
Server
Sample Code
Unfortunately - some browser checking
function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } elseif(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function startRequest() { createXMLHttpRequest(); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", "simpleResponse.xml"); xmlHttp.send(null); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { alert("The server replied with: " + xmlHttp.responseText); } } }
HTML Validator
http://users.skynet.be/mgueury/mozilla/
http://users.skynet.be/mgueury/mozilla/screenshot.html
Checky
http://checky.sourceforge.net/extension.html
http://sourceforge.net/project/screenshots.php?group_id=69729
DOM Inspector
http://www.mozilla.org/projects/inspector/
JSLint
http://www.crockford.com/jslint/lint.html
JsUnit
http://www.edwardh.com/jsunit/
Whats next?
Better tool support - just a matter of time Suns Creator 2 Library/toolkit space will consolidate User expectation will increase More sites will implement
Now what?
Start small Validation is a good rst step Auto complete More dynamic tool tips Partial page updates Recalculate Its all about the user!
Fade Anything
Give me more!
www.ajaxian.com www.ajaxpatterns.org www.ajaxmatters.com/r/welcome www.ajaxblog.com/ http://labs.google.com/ www.adaptivepath.com/
To sum up
Ajax changes the request/response paradigm Its not rocket science, its not a cure all Test it with your users Start slow Embrace change!
Questions?!? Thanks!