我在IE中遇到了這個ajax腳本的問題,因爲它不起作用,它可以在FF和Chrome中完美工作,但是在IE中它根本行不通!有兩個下拉框,根據我在第一個下拉框中選擇的具有所選城市的顯示值的第二個下拉框。ajax腳本在IE中不起作用
<select class="selectDest" name="Prej" onChange="getState(this.value)">
<option></option>
'.funksionet::all_directions().'
</select>
這是第二個下拉框:
<div id="statediv"><select class="selectDest" name="deri">
<option></option>
</select></div>
這是AJAX功能:
<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) {
// only if "OK"
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>
這是findstate.php文件:
<?php
require_once 'includes/constants.php';
$country = $_GET['country'];
$link = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error("1"));
}
mysql_select_db(DB_NAME);
$query="SELECT * FROM costs WHERE prej = '$country';";
$result=mysql_query($query) or die("2");
?>
<select class="selectDest" name="Deri">
<option></option>
<?php while($row = mysql_fetch_array($result)) {
print'<option>'.$row['deri'].'</option>';
}
?>
</select>
我真的需要做這個工作,我會大大的ppreciate如果有人要幫我這個。因爲我不擅長JavaScript!但是如果沒有辦法,我可以做這個跨瀏覽器,那麼我想知道,我不會這樣做。
我會打賭使用[jQuery](http://api.jquery.com/jQuery.ajax/)將解決跨瀏覽器問題。 –
更多的幫助? – TooCooL