Simple AJAX Example

by admin on June 26, 2009
in Ajax

This aims to be the easiest possible example demonstrating AJAX (Asynchronous JavaScript and XML).

AJAX is a technique rather than a technology: It describes how JavaScript can be used to pull data from the server using the XML HTTP Request object and then insert this data into the website using DOM. This is done asynchronously – that is, in the background, without having to refresh the whole page. The technology which AJAX is based on has already been available for a while, the combination is what makes it new.

You can try the examples online or download them and run them locally (except for the PHP script, that would require a webserver with PHP).

1. The DOM

The Document Object Model is the internal representation of your website. The DOM is accessible by JavaScript and provides a way to programmatically insert, remove and modify tags in your website (except that they are called elements or nodes instead of tags, because the DOM manipulates the data model in memory and not the representation as XML). This example shows how to set the content of the

element with the id “foo” to “Hello, AJAX world!”:

<script type="text/javascript">
function replace() {
document.getElementById('foo').innerHTML = "Hello, <b>AJAX</b> world!";
}
</script>
<p><a href="javascript:replace()">Replace Text</a></p>
<div id="foo">
Hello, world!
</div>

Try here: dom.html
Read the Rough Guide to the DOM for more information. Read more…

AJAXing the Web

by admin on June 12, 2009
in Ajax, Javascript

AJAX is one of the hottest new technologies, in the ever growing universe of Web development. In this article, we’ll get to know how AJAX fits in a real-world situation and how you can assess its value in a project. Hopefully, by the time you finish reading this article, you’ll know what AJAX is, why, and how to use it.Nothing really new about what is happening here.

The normal routine in Web development involves requesting a file from the Web Server and receiving a page as response. So whats new with AJAX. Just that the difference, is that requests are being made from the Client side Java Script, which is embedded within HTML.

So what is AJAX ?

AJAX is acronym of Asynchronous Java Script and XML Read more…