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

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:

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;
document.ajax.dyn="Error code " + xhr.status;
};, "data.txt", true);

<FORM method="POST" name="ajax" action="">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dyn" value="">
</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., "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.


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

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.