gpt4 book ai didi

php - ajax 脚本在 IE 中不起作用

转载 作者:行者123 更新时间:2023-11-30 10:49:08 25 4
gpt4 key购买 nike

我在 IE 中使用此 ajax 脚本时遇到问题,因为它不起作用,它在 FF 和 Chrome 中完美运行,但在 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>

我真的需要完成这项工作,如果有人愿意帮助我,我将不胜感激。因为我不擅长 JavaScript!但是,如果我无法跨浏览器执行此操作,那么我想知道,但我不会这样做。

最佳答案

$country = $_GET['country'];
$query="SELECT * FROM costs WHERE prej = '$country';";

我知道,这是题外话,但不好

关于php - ajax 脚本在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6551309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com