By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

How to run Ajax on Local Computer

100+
P: 194
Hi All,

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
  1. xhr.open(GET, "data.txt",  true); 
the error is Get is undefined.

please tell me how i can solve this problem. i am running this code on my local computer.

waiting for reply.

regards

Mohammad Faisal
Jun 25 '08 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
put the GET in quotes ... otherwise it is considered as a variable and you get the shown error message ...

kind regards
Jun 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.