0

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

主机添加.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>

但它显示“使用 xml http 请求时出现问题”的错误。我找不到我犯了什么错误。任何人都可以帮我解决这个问题

4

1 回答 1

1

I pressume your var strURL="findState.php?country="+countryId; is not proper.

Check your browser error console, you can see errors there.

If it is showing 404 page not found, It is because your strURL is not proper check the spelling or path.

于 2013-01-11T07:27:54.067 回答