Small Ajax example

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

once we create XMLHttpRequest() object, then we can request xml data“GET”, url);

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" +

Demo page


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: