PHP and Ajax: An Introduction
Introduction
Ajax is an acronym for Asynchronous Javascript and XML. It is basically a cross-platform mechanism which allows you to make fast, rich and responsive web pages. Using AJAX a coder can avoid reloading the web page when a part of it is changing because of the user interaction. So the AJAX engine which runs within the context of the browser handles basic tasks of validation and oter changes while the script dynamically retrieve some data from the application. This data transfer happens from browser to application in the background and so known as ‘Asynchronous mode of execution’.
Dynamic Script Loading
An alternate to XMLHTTP is dynamic script loading. It has a simple mechanism: you write a javascipt file and in your code you put a <script/> tag and assign the javascript file to its ‘src’ attribute so that it can be loaded when required. The following code explains this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example 1
<script type=”text/javascript”>//
function makeRequest() {
var oScript = document.createElement("script");
oScript.src = "example1.js";
document.body.appendChild(oScript);
}
function callback(sText) {
alert("Loaded from file: " + sText);
}
//]]>
</script>
</head>
<body>
<input type=”button” value=”Click Me” onclick=”makeRequest()” />
</body>
</html>
So you can see the <script/> element is created using the DOM createElement() method and add it to the page.
var oScript = document.createElement(”script”);
oScript.src = “/path/to/my.js”;
document.body.appendChild(oScript);
When the new <script/> element is actually added to the page then only downloading starts. Once downloading is done the JavaScript code is interpreted. The callback function is used to indicate that the code has finished being loaded and interpreted.
Comments
Write a comment
You must be logged in to post a comment.

Comment from Baby Stroller Web Directory
Time: April 22, 2008, 1:46 pm
Cross platform mechanism like Ajax are compatible with most of the language. Google is the best example of Ajax. Most of the functionality are implemented using Ajax in google search engine.