AJAX sample program to see the contents of a text file ~ Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples
Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples: AJAX sample program to see the contents of a text file

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>


Related Posts by Categories

2 comments:

Anonymous said...

Should I use an HTTP GET or POST for my AJAX calls?

Anonymous said...

AJAX requests should use an HTTP GET request when retrieving data where the data will not change for a given request URL. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture

Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex