Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: It doesn't work

  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks WolfShade I will check the console.

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #8
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #10
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #11
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •