473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to run Ajax on Local Computer

194 100+
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
1 10769
gits
5,390 Expert Mod 4TB
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

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

Similar topics

1
by: delu | last post by:
Can anybody teach me how to write a code using asp, so that i can downlaod file from server to a fixed folder on local computer? Best regards
3
by: GTi | last post by:
Is it possible to interact with local computer in some way with JavaScript ? Like sending a message (SendMessage/PostMessage) to a local program. I want to write a service; installed on the...
9
by: sifar | last post by:
Hi, I am right now learning PHP & want to know if there is a way to send web form data to an Excel sheet located on a network. My windows xp PC doesnot have a copy of Excel. Also i am not...
2
by: priyamjm | last post by:
I would like to write a Windows Service app that will be notified when an interactive user logs on/off the local computer. Thanks in advance Priyakant
2
by: Lou Civitella | last post by:
I created a web site with ASP.Net 2.0. I uploaded it to my web site and everything works fine. Now I want to be able to run the site on my local computer but I cannot. When I try to open the...
0
by: jhaek19 | last post by:
hi! do you have a code on how to copy files from local computer to remote computer? please help: when I run this code, it gives an error, File not Found or Path not Found... code: FileFrom =...
0
by: tanyali | last post by:
using php5, I download files : ******** downloadfile.php $fileContent = @mysql_result($result1,$i,"gdata"); ...
4
by: salon | last post by:
i have created a web application in c# and ASP.NET1.1 that is having a button on click of which spawns a web page which is hosted on my localhost! i have given the URL to my friend.Now he/she...
0
by: santhanalakshmi | last post by:
Hi, I installed MSSQL 2008 in my local system. After installation process gets completed, i login as LOCAL(127.0.0.1). The MSSQL connected for me and i worked for a day very finely. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.