关于ajax的问题

xbolton 2007-11-30 06:41:19
原先没用过,现在找了一些现成的代码自己研究然后按自己要求修改,但出现一个错误

行:31
字符:3
代码:0
错误:未指明的错误。

代码如下

<script language="javascript" type="text/javascript">
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}

function order_count() {
var url = "order_count.asp";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}

function updatePage() {
if (xmlHttp.status == 200){ var response = xmlHttp.responseText;
test1.innerHTML=response;
setTimeout("order_count();",5000);
}
}
order_count();
</script>


红色的就是错误所指位置

请大家帮忙看一下,谢谢
...全文
109 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tantaiyizu 2007-12-03
  • 打赏
  • 举报
回复

谢tantaiyizu的回答

不过还是不行啊,用以上代码的话,提示test1未定义

-------

document.getElementById("test1").innerHTML = response;
xbolton 2007-12-03
  • 打赏
  • 举报
回复
谢谢tantaiyizu的回答

不过还是不行啊,用以上代码的话,提示test1未定义
西安风影 2007-12-03
  • 打赏
  • 举报
回复
代码没看出问题
对于初学者要注意一点。
AJAX的运行必须将
HTML页面部署到IIS上才可以正常运行,因为xmlHttp.send(null); 就是要请求服务器。
而直接双击HTML运行是没有效果的
tantaiyizu 2007-12-03
  • 打赏
  • 举报
回复
function   order_count()   { 
var url = "order_count.asp";
xmlHttp.open("POST", url, false);
//xmlHttp.onreadystatechange = updatePage; 不需要
xmlHttp.send(null);

var response = xmlHttp.responseText;
test1.innerHTML=response;
setTimeout("order_count();",5000);
}


--

这样即可!
xbolton 2007-12-03
  • 打赏
  • 举报
回复
不是吧,很难解决吗?
还是不管它,不影响使用就这样了?
tantaiyizu 2007-12-03
  • 打赏
  • 举报
回复
高难问题
xbolton 2007-12-03
  • 打赏
  • 举报
回复
过了2天了都没人帮忙啊……
xbolton 2007-12-03
  • 打赏
  • 举报
回复

function updatePage() {
try{
if (xmlHttp.status == 200){
var response = xmlHttp.responseText;
test1.innerHTML=response;
setTimeout("order_count();",5000);
}
}catch(e){}
}


解决了,是浏览器的问题咯?

谢谢tantaiyizu了,(看到你一直在改昵称啊,呵呵。 在哪里改呢...)
tantaiyizu 2007-12-03
  • 打赏
  • 举报
回复

function updatePage() {
if (xmlHttp.status == 200){ var response = xmlHttp.responseText;
test1.innerHTML=response;
setTimeout("order_count();",5000);
}
}

--

function updatePage() {
try{
if (xmlHttp.status == 200){
var response = xmlHttp.responseText;
test1.innerHTML=response;
setTimeout("order_count();",5000);
}
}catch(e){}
}
xbolton 2007-12-03
  • 打赏
  • 举报
回复
是不是<span id="test1"></span>

其实我已经说了,原来的代码如果不去关心错误的话,运行下来显示的结果都是正常的。

我因为刚用ajax,所以不清楚document.getElementById对象是什么类型?需要
tantaiyizu 2007-12-03
  • 打赏
  • 举报
回复


你页面有 test1 这个控件吗?
xbolton 2007-12-03
  • 打赏
  • 举报
回复

function order_count() {
var url = "order_count.asp";
xmlHttp.open("POST", url, false);
xmlHttp.send(null);

var response = xmlHttp.responseText;
document.getElementById("test1").innerHTML.innerHTML=response;
setTimeout("order_count();",5000);
}



错误:'document.getElementById(...)' 为空或不是对象
xbolton 2007-11-30
  • 打赏
  • 举报
回复
对了,执行下来倒算是正常,但浏览器下面老是提示Script Error!,一下有3个一样的错误,我的页面每5秒刷新一次的话,累计就越来越多了。




以前就来这里找找东西,刚来这里,发现发了帖不能编辑?

52,797

社区成员

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

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