0
나는 하나의 select listbox를 데이터베이스의 값으로 동적으로 채우는 인터넷에서 간단한 AJAX 데모 코드를 얻었다. 여기에는 AJAX 코드가 포함 된 html 파일과 PHP 파일이 포함되어 있습니다.ajax 코드가 IE, chrome, FireFox5.0에서는 작동하지만 FireFox 3에서는 작동하지 않는 이유는 무엇입니까?
이 코드는 IE, Chrome, FireFox4에서 잘 작동하지만 FireFox3에서는 작동하지 않습니다. 어느 누구도 이것을 설명하고 해결책을 말해주십시오. 참조를 위해 다음과 같이 코드는
에
id tinyint(4) primary key not null
city varchar(50)
countryid tinyint(4)
HTML 파일
<html>
<head>
<script type="text/javascript">
function getCity(strURL)
{
alert("inside getCity function");
//var req = getXMLHTTP(); // function to get xmlhttp object
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
//xmlhttp=new XMLHttpRequest();
req=new XMLHttpRequest();
}
else
{// code for IE6, IE5
//xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4) { //data is retrieved from server
if (req.status == 200) { // which reprents ok status
document.getElementById('citydiv').innerHTML=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n");
}
}
}
//alert(srtURL);
var sURL="findcity.php?country="+strURL;
req.open("GET", sURL, true); //open url using get method
req.send();
}
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
Country : <select name="country" onChange="getCity(this.value)">
<option value="">Select Country</option>
<option value="1">india</option>
<option value="2">usa</option>
</select>
<br />City : <div id="citydiv">
<select name="select">
<option>Select City</option>
</select>
</div>
</form>
</body>
</html>
PHP 파일
<?
echo $_GET['country'];
echo "<br>";
$country=intval($_GET['country']);
echo $country;
echo "<br>";
$link = mysql_connect('localhost', 'root', 'mark'); //change the configuration if required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('querytest'); //change this if required
$query="select city from city where countryid=$country";
echo "<br>";
echo $query;
echo "<br>";
$result=mysql_query($query);?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['city']?></option>
<? } ?>
</select>
나에게 안내하십시오 친구를 다음과 같이 도시 테이블에 대한 데이터베이스 스키마입니다 이 코드가 FireFox 3에서 작동하도록하십시오.
에? –
디버깅을 할 수 있습니까? 어떤 오류 메시지가 보이나요? – TJHeuvel
그래서 작동하지 않는 것은 무엇입니까? – Ibu