www.webdeveloper.com
Results 1 to 8 of 8

Thread: AJAX Ready State Never Reaches 200

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    AJAX Ready State Never Reaches 200

    So I'm new to javascript and I'm actively trying to learn it for work. However, the project I've been working on has come to a screeching halt because my program never reaches the 200 ready state. can anyone help?
    Code:
    <html>
    <head>
    <script>
    function queryDB(cpid, radar, year, month, day)
    {
    if (day=="")
      {
      document.getElementById("result").innerHTML="";
      return;
      }
    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()
      {
      alert(xmlhttp.readyState + " " + xmlhttp.status);
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("result").innerHTML=xmlhttp.responseText;
        }
      }
    var url="query.php?cpid="+cpid+"&radar="+radar+"&year="+year+"&month="+month+"&day="+day;
    xmlhttp.open("GET",url, true);
    xmlhttp.send();
    }
    
    </script>
    </head>

  2. #2
    Join Date
    Mar 2011
    Posts
    1,159
    You're using a relative URL in your AJAX request. Based on your code, you need to be sure that 'query.php' resides in the same directory as the HTML page. If it does, test the query.php script itself by entering the complete URL in your browser to make sure it's responding properly.

  3. #3
    Join Date
    Dec 2012
    Posts
    4
    i just ran a test where i had an alert set to show where it is in the ready state. it would reach 4/200, display it but then tit would return to 1/0 and the results would be gone
    Code:
    xmlhttp.onreadystatechange=function()
      {
      alert(xmlhttp.readyState + " " + xmlhttp.status);
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("result").innerHTML=xmlhttp.responseText;
        }
      }

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by bodweiser View Post
    i just ran a test where i had an alert set to show where it is in the ready state. it would reach 4/200, display it but then tit would return to 1/0 and the results would be gone
    What happens after that, does it keep making requests?
    Can you show how the function is being called?

  5. #5
    Join Date
    Dec 2012
    Posts
    4
    it produces 5 alerts:
    1 0
    2 200
    3 200
    4 200
    1 0
    after i click ok on the 4 200, i see the results appear on the page, then after i click ok on the 1 0 alert, the results are gone.

    the script is called from this form:
    Code:
    <form>
    CPID:<input type="text" name="cpid" id="cpid"/>
    Radar:<select name="radar" id="radar">
    <option value="all">All Radars</option>
    <option value="bks">Blackstone</option>
    <option value="cve">Christmas Valley East</option>
    <option value="cvw">Christmas Valley West</option>
    <option value="fhe">Fort Hays East</option>
    <option value="fhw">Fort Hays West</option>
    <option value="wal">Wallops</option>
    <option value="gbr">Goose Bay</option>
    <option value="kap">Kapuskasing</option></select>
    
    Year:<select name="year" id="year">
    <option value="all">All Years</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option></select>
    
    Month: <select name="month" id="month">
    <option value="all">All Months</option>
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option></select>
    
    Day: <select name="day" id="day">
    <option value= "all">All Days</option>
    <?PHP
    for($x=1; $x<32; $x++){
            echo "<option value= \"$x\">$x</option>";
    }
    ?>
    </select>
    <input type="submit" value="Query" onClick="queryDB(document.getElementById('cpid').value,  document.getElementById('radar').value, document.getElementById('year').value,document.getElementById('month').value, document.getElementById('day').value);"/></form>
    
    <div id="result">
    </div>

  6. #6
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    readyState should never get that high, i think you mean status...

  7. #7
    Join Date
    Dec 2012
    Posts
    4
    Quote Originally Posted by rnd me View Post
    readyState should never get that high, i think you mean status...
    yes thats what i meant

  8. #8
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by bodweiser View Post
    Code:
    <input type="submit" value="Query" onClick="queryDB(document.getElementById('cpid').value,  document.getElementById('radar').value, document.getElementById('year').value,document.getElementById('month').value, document.getElementById('day').value);"/></form>
    You're doing nothing to suppress submission of the form, so all bets are off.

    Add return false after the function call.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles