AJAX响应文本中没有数据

Right up front...I am very new to using Ajax.

I'm working on a web site where I want the results of one Select object to determine the options in the second Select object(from a database query). I'm using PHP and it appears that the only way to do this is to use Ajax. I've written a short html page to test my Ajax knowledge and it seems to work just find on Firefox but not on Chrome or IE. I've done a lot of research and found all sorts of folks with similar problems but no real solution.

I'm making the XMLHTTPRequest call to a local file in the same folder even so I should not be experiencing any cross-domain problems. Any help would be greatly appreciated.

Here's my Javascript function that gets called when the Select box is changed: ...

   function getData(str)
    {
    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.open("GET","ajax_info.php?color=",true);
    xmlhttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.send();
    alert(xmlhttp.responseText);
  }

********ajax_info.php +++++++++++++++++++++ //this is the php file that runs in response to the xmlhttprequest. It just generates a string of number at this time.

<?php
$str = "";
$i = 0;
for($i; $i<1000; $i++)
 { 
 $str = $str.$i."-";
}
echo $str;
?>

You need to attach an event handler to your xmlhttp object to catch the onreadystatechange event. Note that when you alert your value, the asynchronous ajax call has just fired and has not finished yet (you are not checking for that anyway):

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        alert(xmlhttp.responseText);
    }
}
xmlhttp.open("GET","ajax_info.php?color=",true);
xmlhttp.setRequestHeader("Content-Type", "text/xml");
xmlhttp.send();

Well in that case you should try jQuery. It will be lot easier for you to make ajax request.

Here is an example for your problem

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<script>

// FOR GET REQUEST

$.get("ajax_info.php",{color:'value'},function(data) {

            alert(data); // RETRIEVE THE RESULT
});

</script>