IE中无法使用对象吗
我刚学ajax,创建xmlhttp对象的时候无法创建,但在firefox中好用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<label>
<input name="ttt" type="text" id="ttt" />
</label>
<input type="button" name="Button" value="Button" onclick="start()"/>
</form>
<p> </p>
<p>
<label></label>
</p>
</body>
</html>
<script type="text/javascript">
var xmlHttp;
function createXH(){
if (window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
alert(1);
} else if (window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
alert(2);
}
}
function start(){
createXH();
xmlHttp.onreadystatechange =callback;
xmlHttp.open("GET","d.jsp?=id"+document.form1.ttt.value,true);
xmlHttp.send(null);
}
function callback(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
alert("result:"+xmlHttp.responseText);
}
}
}
</script>
难道是IE的安全级别高,不允许建立Active对象吗
问题点数:20、回复次数:11Top
1 楼pli0825(念叨念叨,我念叨死你!)回复于 2006-03-20 11:14:19 得分 15
function InitAjax()
{
var httpAjax = null;
try
{
httpAjax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1)
{
try
{
httpAjax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2)
{
}
}
if(!httpAjax && XMLHttpRequest != 'undefined')
{
httpAjax = new XMLHttpRequest();
}
return httpAjax;
}Top
2 楼theoffspring(崽子)回复于 2006-03-20 11:20:34 得分 0
还是说"不支持这个操作"Top
3 楼theoffspring(崽子)回复于 2006-03-20 11:53:01 得分 0
发现其中一个错误是函数名不能叫start,因为这是个系统关键字,换成start2以后虽可创建xmlhttp对象了,但调用的页面还是没有弹出对话框显示其内容啊Top
4 楼iuhxq(小灰)回复于 2006-03-20 12:00:59 得分 5
把start改为start1即可Top
5 楼theoffspring(崽子)回复于 2006-03-20 12:10:45 得分 0
问题找到了,ie中好像xmlhttp没有responseText这个属性啊,在这行后面就执行不到了,在它前面都能执行到Top
6 楼theoffspring(崽子)回复于 2006-03-20 13:09:06 得分 0
怎么办啊Top
7 楼pli0825(念叨念叨,我念叨死你!)回复于 2006-03-20 13:12:44 得分 0
那就是你其他代码的问题了
IE支持这个没有问题的。我用过了Top
8 楼pli0825(念叨念叨,我念叨死你!)回复于 2006-03-20 13:14:54 得分 0
responseText的使用也没问题。看看其他代码方面吧。Top
9 楼theoffspring(崽子)回复于 2006-03-20 13:30:40 得分 0
页面d.jsp如果后面带参数,就不好用,没有参数就好用,但我看书上的例子,servlet带参数都是好用的,我这个为什么不行Top
10 楼theoffspring(崽子)回复于 2006-03-22 08:41:23 得分 0
dingTop
11 楼theoffspring(崽子)回复于 2006-03-24 11:18:46 得分 0
last dingTop




