I am new in the Ajax. I want to know how i can run Ajax code in my local computer. For example i am using the following code to get the text of a text file named data.txt:
[HTML]<html>
<head>
<script>
function submitForm()
{
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
document.ajax.dyn="Received:" + xhr.responseText;
else
document.ajax.dyn="Error code " + xhr.status;
}
};
xhr.open(GET, "data.txt", true);
xhr.send(null);
}
</script>
</head>
<body>
<FORM method="POST" name="ajax" action="">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dyn" value="">
</FORM>
</body>
</html> [/HTML]
The file is located in the same directory where this HTML file is saved. When i click on the submit button i am getting an error on the line:
Expand|Select|Wrap|Line Numbers
- xhr.open(GET, "data.txt", true);
please tell me how i can solve this problem. i am running this code on my local computer.
waiting for reply.
regards
Mohammad Faisal