在我的页面中,我有以下代码
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>
但它显示“使用xml http请求时出现问题”的错误。我无法发现我做了什么错误。任何人都可以帮我解决这个问题
答案 0 :(得分:1)
我按下你的var strURL="findState.php?country="+countryId;
不合适。
检查浏览器错误控制台,可以看到错误。
如果显示404页面未找到,那是因为你的strURL不正确检查拼写或路径。