Archive for Ajax

Small Ajax example

Posted in Programming with tags , on November 17, 2006 by wsjoung

JavaScripts create XMLHttpRequest() object first.
req = new XMLHttpRequest();

once we create XMLHttpRequest() object, then we can request xml data
req.open(“GET”, url);
req.send(null);

then check onreadystatechange state
req.onreadystatechange = processReqChange;

it has 5 states (0-4)and 4 means completed retrieving data

function processReqChange() {
// only if req shows "complete"
if (req.readyState == 4) {
// only if  "OK"
if (req.status == 200) {
// ...processing statements go here...
response = req.responseXML;

if (response) {
// do something with XML contents
} else {
// no XML contents
}

} else {
alert("There was a problem retrieving the XML data:n" +
req.statusText);
}
}
}

Demo page

Advertisements

Ajax (Asynchronous JavaScript and XML)

Posted in Programming with tags , on November 17, 2006 by wsjoung

Asynchronous JavaScript and XML, I can explain this with just one picture.


98146589_99749e538f.jpg

This picture show us that the browser doen’t connect to a websever to get html pages any more. for example, if you open gmail.com, then you will get bunch of xml document instead of html.
with those xml document, the JavaScript will generate proper html pages.
it’s pretty simple concept, huh?

Wikipedia says
Simple tutorial
Ajax blog
Java BluePrints Solutions Catalog
Technical article