依赖于Ajax的下拉值不会获取这些值


Ajax dependent dropdown value is not fetching the values

在我的页面中,我有以下代码

hostadd.php

<script language="javascript" type="text/javascript">
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;
}
function getState(countryId) {      
    var strURL="findState.php?country="+countryId;
    var req = getXMLHTTP();
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                if (req.status == 200) {
                    document.getElementById('statediv').innerHTML=req.responseText;                     
                } else {
                    alert("There was a problem while using XMLHTTP:'n" + req.statusText);
                }
            }               
        }           
        req.open("GET", strURL, true);
        req.send(null);
}       
}
</script>

<div style="margin-left: 51px;">State:
    <select name="country" id="country" onChange="getState(this.value)" style="margin-left: -3px;">
        <option ></option>
        <?php $qr = mysql_query("select * from ctm_state ");
        while($data= mysql_fetch_array($qr))
        {?>
            <option value="<?php echo $data['id']; ?>"><?php echo $data['state']; ?></option>
        <?php } ?>
    </select>
</div>

findstate.php

<? $country=intval($_GET['country']);
include("../config/config.php");
$query="SELECT id,location FROM ctm_locationname WHERE stateid='$country'";
echo $query;
$result=mysql_query($query);
if($result)
{
    echo "success";
}
else
{
    echo "cant fetch";
}
?>
<div  style=""> location:<select name="state" id="state">
<option></option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['location']?>><?=$row['location']?></option>
<? } ?>
</select></div>

但是它显示了错误"There was problem using xml http request"。我找不出我犯了什么错误。任何人都可以帮我解决这个问题

我想你的var strURL="findState.php?country="+countryId;不合适。

检查你的浏览器错误控制台,你可以在那里看到错误。

如果显示404页面未找到,这是因为你的url不正确检查拼写或路径