AJAX sample program to see the contents of a text file

// JavaScript Document
//ajaxtest.js
function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
xhr = false;
}
}
}
return xhr;
}

function getFile(file) {
var request = getHTTPObject();
if (request) {
request.onreadystatechange = function() {
displayResponse(request);
};
request.open("GET", file, true);
request.send(null);
}
}

function displayResponse(request) {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
alert(request.responseText);
}
}
}

<html>
<head>
<title>Using XMLHttpRequest<⁄title>
<script type=""text/javascript" src="ajaxtext.js"><⁄script>
<⁄head>
<body>
<p>
<a href=""message.txt" onclick="getFile(this.href);
return false;">
Click here to see the contents of a text file

<⁄a>
<⁄p>
<⁄body>
<⁄html>


Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex