Php Ajax Country City Select Menu onChange()不工作

Php Ajax Country City Select Menu onChange()不工作,php,javascript,ajax,onchange,Php,Javascript,Ajax,Onchange,我遇到了一个创建可以动态更改的下拉菜单的优秀教程 这里是链接 这是演示 我在稍微修改代码,跳过了选择状态的部分 下面是findCity.php文件 <!--//---------------------------------+ // Developed by Roshan Bhattarai | // http://roshanbh.com.np | // Contact for custom scripts | // or imple

我遇到了一个创建可以动态更改的下拉菜单的优秀教程

这里是链接

这是演示


我在稍微修改代码,跳过了选择状态的部分

下面是findCity.php文件

<!--//---------------------------------+
//  Developed by Roshan Bhattarai    |
//  http://roshanbh.com.np           |
//  Contact for custom scripts       |
//  or implementation help.          |
//  email-nepaliboy007@yahoo.com     |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>

<? $country = $_GET['country'];
$link  = mysql_connect("snip","snip","snip");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('snip');
$query="SELECT city FROM location WHERE country='$country'";
$result=mysql_query($query);

?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['city']?></option>
<? } ?>
</select>
有什么想法吗

补充说明

function getXMLHTTP() { //function to return the xml http object
        var xmlhttp=false;  
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {       
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }

        return xmlhttp;
    }

您在测试页的代码中有语法错误:

if (req.readyState == 4 {
当然应该是:
if(req.readyState==4)


如果这不能解决问题,我们可以尝试其他方法。:)

页面上有一个javascript错误,@nevermind比我先指出。那很好,但你还有另一个问题,这似乎只是你这边的误解。线路

req.onreadycountrychange = function() {
没有意义,需要改为:

req.onreadystatechange = function() {
函数名
onreadystatechange
在这种情况下有点混乱,但它与“State/Country”中的“State”没有任何关系。这是指
XMLHttpRequest
对象的当前状态。基本上,只要更新请求对象的状态,就会调用该函数,
onreadystatechange

请在此处阅读更多信息:

req.onreadystatechange = function() {