Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2012, 10:30 AM   PM User | #1
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
It doesn't work

Hi,
I read about ajax calls and I thought that ajax calls was the solution to my problem in creating a chat room. After I had read the tutorial carefully, I tried to write my own ajax call code and when i uploaded the file to a free server it didn't work. I thought that maybe the code was wrong, but when i read it again it was correct. So I went to the tutorial and I copied the example code that I knew it was working. I created all the necessary files for the example to work, but again nothing happened. What I am trying to do is to access a txt file and read its content. Another thing with my server is that when i try to access a txt file, a white blank page is the result, when in other servers when I access a txt file i get the content of the file. My question is: Is it possible that a server does not support ajax calls?
A-man is offline   Reply With Quote
Old 07-31-2012, 01:26 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Not that I am aware of. AJaX is JavaScript (client-side) and XML. When you use AJaX to asynchronously access a script on the server, it is usually doing so in the background, seamlessly working. Check browser error console for messages.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 07-31-2012, 03:33 PM   PM User | #3
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
Thanks WolfShade I will check the console.
A-man is offline   Reply With Quote
Old 07-31-2012, 05:04 PM   PM User | #4
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
You were right WolfShade.
I get a 404 error., However I have created the file. What are the possible reasons for that error and how can resolve the problem?
A-man is offline   Reply With Quote
Old 07-31-2012, 07:08 PM   PM User | #5
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
A 404 error is "not found". Are you sure you typed the path to the file correctly?
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 07-31-2012, 08:53 PM   PM User | #6
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
The name of the txt file is test.txt and it is located in the same folder as the html file that contains the AJaX call. The code that I have write is the following.

<CODE>
<html>

<head>
<title>Test</title>

</head>

<body>
Procedure started
<script type="text/javascript">

var myrequest;
kala();
function kala() {

if (window.XMLHttpRequest) {
myrequest=new XMLHttpRequest();

}
else {
myrequest= new ActiveXObject('Microsft.XMLHTTP');
}

myrequest.open("GET",'test.txt',true);
myrequest.send(null);
myrequest.onreadystatechange=getData();


}
function getData() {
if (myrequest.readyState===4) {
if (myrequest.status===200) {
var text=myrequest.responseText;
alert(text);

}

}

}
</script>

</body>

</html>
</CODE>
Please let me know if I miss something.
A-man is offline   Reply With Quote
Old 07-31-2012, 09:19 PM   PM User | #7
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
To wrap code in tags, use square brackets, not greater-than and less-than:

Code:
<html>

<head>
<title>Test</title>

</head>

<body>
Procedure started
<script type="text/javascript">

var myrequest = new kala();

 myrequest.open("GET",'[url to your server]/test.txt',true);
 myrequest.send(null);
 myrequest.onreadystatechange=getData();

function kala() {

if (window.XMLHttpRequest) {
return new XMLHttpRequest();

}
else {
return new ActiveXObject('Microsft.XMLHTTP');
}

}
function getData() {
if (myrequest.readyState===4) {
if (myrequest.status===200) {
var text=myrequest.responseText;
alert(text);

}

}

}
</script>

</body>

</html>
Untested, but I think this will do it.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 08-01-2012, 03:07 PM   PM User | #8
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
Thanks, but it didn't work.
Is it normal that when i try to access the txt file with the browser i get an empty page when the file is not empty?
A-man is offline   Reply With Quote
Old 08-01-2012, 05:51 PM   PM User | #9
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Quote:
Originally Posted by A-man View Post
Thanks, but it didn't work.
Is it normal that when i try to access the txt file with the browser i get an empty page when the file is not empty?
That depends upon what is in the txt file. If it's XML or HTML code without content, it can appear blank. Do a "View Source" to see if it really is blank.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 08-01-2012, 06:42 PM   PM User | #10
A-man
New to the CF scene

 
Join Date: Jul 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
A-man is an unknown quantity at this point
Thank you very much for your help WolfShade.
I change the server and the problem of the txt file solved.
So it probably was the server's fault.
A-man is offline   Reply With Quote
Old 08-01-2012, 07:20 PM   PM User | #11
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Glad that changing server was the solution.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:34 AM.


Advertisement
Log in to turn off these ads.