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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Ajax code always says readystate never from changes 1 & response text is null always

    This is my html code
    *************************************************
    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","ajax_info.txt",true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <div id="myDiv"><h2>Let AJAX change this text</h2></div>
    <button type="button" onclick="loadXMLDoc()">Change Content</button>

    </body>
    </html>
    ********************************************************
    ajax_info.txt
    *************************************************
    Hi this is text file

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Are you running this code on an actual webserver or locally (file based)?

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi devnull69,I am running this locally file based Using Eclipse PDT.
    I tried it even using response from php..it didn't work out.....
    And my workspace is htdocs folder whose location is C:\xampp\htdocs
    I start apache server using xampp and run the above code from eclipse..
    I have spent a day searching about the problem..it would be really gr8full if you do some favor....

    when i run admin.html a browser tab with url=http://127.0.0.1:8020/Admin/admin.html opens up.
    when i click the button nothing loads...i used firebug to detect the issue..
    I found that ready state never changes from 1...
    Responsetext is always empty string...
    Please feel free to ask any further info...
    Thank you for your kind reply...

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    I can't say anything about the constellation eclipse/xampp but judging from your quote
    I am running this locally file based
    I'd have to say: Ajax requests are only possible if the two pages (the one initiating and the one receiving the request) are running on the same WEBSERVER. Just opening up a local .html file and running its javascript connecting to another local file will NOT work.

    EDIT: Another hint I had to learn some time ago: Please specify the onreadystatechange assignment AFTER the .open() line otherwise it won't work correctly on some browsers/configurations.

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am pleased by your response!Thank you!will try running on the same WEBSERVER....


  •  

    Tags for this Thread

    Posting Permissions

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