Php javascript/ajax下拉列表在IE中不起作用

Php javascript/ajax下拉列表在IE中不起作用,php,javascript,ajax,xmlhttprequest,Php,Javascript,Ajax,Xmlhttprequest,我试图根据类别选择列表中选择的内容,将值添加到子类别的选择列表中。这似乎对IE不起作用。有人能提出这个问题吗 我的代码可以在firefox、Chrome、Opera和Safari中正常工作 但在IE7、8、9中不起作用 js代码: <!-- Begin CHack For Ostan --> function getOstan(str) { if (str.length==0) { document.getElementById("SH_O").innerHTML="";

我试图根据类别选择列表中选择的内容,将值添加到子类别的选择列表中。这似乎对IE不起作用。有人能提出这个问题吗

我的代码可以在firefox、Chrome、Opera和Safari中正常工作 但在IE7、8、9中不起作用

js代码:

<!-- Begin CHack For Ostan -->
function getOstan(str)
{
if (str.length==0)
  { 
  document.getElementById("SH_O").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("SH_O").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","listing.php?q="+str,true);
xmlhttp.send();
}
<!-- END -->
<!-- Begin CHack For City -->
function getSH_O(str)
{
if (str.length==0)
  { 
  document.getElementById("SH_C").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("SH_C").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","listing.php?z="+str,true);
xmlhttp.send();
}
<!-- END -->

函数getOstan(str)
{
如果(str.length==0)
{ 
document.getElementById(“SH_O”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“SH_O”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“listing.php?q=“+str,true”);
xmlhttp.send();
}
函数getSH_O(str)
{
如果(str.length==0)
{ 
document.getElementById(“SH_C”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“SH_C”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“listing.php?z=“+str,true”);
xmlhttp.send();
}
在FF中:

如果IE:

< Bu >你应该考虑使用一个能为你做工作的库,比如jQuery(测试,跨浏览器等)


有些东西告诉我,你可以用jQuery在三行中跨浏览器完成这项工作,我甚至没有读过代码,只是说?添加图片,请重新检查问题这可能不是ajax问题,即可能不允许你使用
innerHTML
添加select的选项。
function getXHRequest() {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

var xmlhttp = getXHRequest();
xmlhttp.open("GET","listing.php?z="+str,true);
xmlhttp.send();
$.ajax({url: "listing.php?z="+str}).done(function(data){
    $("SH_C").html(data);
});