I’m new to AJAX. Trying to write a program that requests a file from a server and displays the text in the requested file. Not having any luck. Nothing happens when I click on the button. Here’s the code:
[CODE]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<body>
<head>
<title>Intro to AJAX–create and send an XMLHttpRequest object to the server</title>
<script type=”text/javascript” language=”javascript”>
<!–The object detection code –>
function goAjax()
{
var req = null;
// Is there support for native XHR object?: IE7+, Firefox, Safari, Opera
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
//create an XMLHttpRequest object
}
else if (window.ActiveXObject)
//check for Version 6
{
req = new ActiveXObject(‘MSXML2.XMLHTTP.6.0’);
//create an ActiveX XMLHTTP component
}
if (!req)
{
req = new ActiveXObject(‘MSXML2.XMLHTTP’);
//fallback to version 3
}
//Request data to be retrieved from the server
req.onreadystatechange = function() {
if(req.readyState == 4) {
document.form1.message.value = req.responseText; }
else {
document.form1.message.write(“Retrieving message. One moment…”);
}
}
goAjax.open(“GET”, “message2.txt”, “true”);
goAjax.send(null);
}
//–>
</script>
</head>
<form name=”form1″>
Name: <input type=”text” size=”50″ name=”message”> <br />
Click the button to get the message: <input type=”button” value=”Go Get It!” onClick=”goAjax()”>
</form>
</body>
</html>