Fetching data with Ajax - Sample AJAX Program ~ Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples
Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples: Fetching data with Ajax - Sample AJAX Program

Fetching data with Ajax - Sample AJAX Program

<html>
<head>
<title>Ajax at work</title>

<script language = "javascript">
function getData(dataSource, divID)
{
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new
ActiveXObject("Microsoft.XMLHTTP");
}

if(XMLHttpRequestObject) {
var obj = document.getElementById("targetDiv");
XMLHttpRequestObject.open("GET", dataSource);

XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.style.color = "#FF0000";
obj.innerHTML = XMLHttpRequestObject.responseText;
setTimeout(dimmer, 500);
}
}

XMLHttpRequestObject.send(null);
}
}

function dimmer()
{
var obj = document.getElementById("targetDiv");
obj.style.color = "#000000";
}
</script>
</head>

<body>

<H1>Fetching data with Ajax</H1>

<form>
<input type = "button" value = "Display Message"
onclick = "getData('data.txt', 'targetDiv')">
</form>

<div id="targetDiv">
<p>The fetched data will go here.</p>
</div>

</body>
</html>

Related Posts by Categories

0 comments:

Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex