调试了一个星期苦逼ajax,除了IE其它均能获取数据,求高人!

一只小老贺 2012-05-04 11:46:12
不多说了,直接上源码,高手们帮帮我这只笨鸟吧,就只有IE不能显示,坑爹的。功能是类似那种省市联动
<script>
function ajax(){
val = document.getElementById("Sort_One").value
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("SortOne").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax.asp?t="+Math.random()+"&val="+val,true);
xmlhttp.send();
//xmlhttp.open("POST","ajax.asp",true)
//xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//xmlhttp.send("val="+val+"&t="+Math.random());
}
</script>



	
val = request("val")

sortone_sql = "select * from Phone_SortOne where Content_Sort_ID="&val

set query_SortOne = Conn.execute("select * from Phone_SortOne where Content_Sort_ID="&val)
while not query_SortOne.eof
response.write "<option>"&query_SortOne("Content_SortOne_Name")&"</option>"
query_SortOne.movenext
wend
...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
001007009 2012-05-04
  • 打赏
  • 举报
回复
楼主看看这个例子 就知道 你做的在ie下无效果的原因了
在ff 和 ie 下对比看

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<select id="test"></select>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
$('test').innerHTML = '<option>1</option>'
</script>
</body>
</html>




ie 需要 用 new Option 这样 动态加
snow-is-my-Love 2012-05-04
  • 打赏
  • 举报
回复
兼容问题 汗~
1楼说的好!
pt1314917 2012-05-04
  • 打赏
  • 举报
回复
这是IE 的一个BUG,微软的BUG申明中注明了两种解决方案:
1. 如果您必须使用 innerHTML ,一种替代方法是使用一个 div 对象封装 SELECT 元素和然后设置 div 对象的 innerHTML 属性。
如:

<div id="div1">
<select id="sel1" ></select>
</div>
<script>
window.onload=function(){
document.getElementById("div1").innerHTML="<select id='sel1'><option>a</option></select>";
}
</script>

2、使用new Option()对象,然后添加到下拉框控件中。
推荐使用这种。

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧