Quantcast
Viewing all articles
Browse latest Browse all 3

Small Ajax example

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


Viewing all articles
Browse latest Browse all 3

Trending Articles