xmlhttprequest alert(xmlhttp.readystate); 提示未定义

生活的信仰 2010-11-30 10:57:15



var xmlhttp = null ;
function getxml()
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return xmlhttp;
}


function check()
{
var rolename = document.getElementById("rolename").value;
alert(rolename);
xmlhttp = getxml();

if(xmlhttp)
{
alert ("ok");
xmlhttp.open("GET","ajax.aspx?rolename="+escape(rolename),true);
alert("op()");

xmlhttp.onreadystatechange = callback;
xmlhttp.send(null);
}
else
{
alert ("xmlhttp lost");
}
}

function callback()
{
alert("callback");

alert(xmlhttp.readystate);
if(xmlhttp.readystate ==4)
{
alert("rr");
if(xmlhttp.status ==200)
{
alert("gggg");
var nn = xmlhttp.responseText;
alert(nn);
}
}
}



...全文
160 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
生活的信仰 2010-12-01
  • 打赏
  • 举报
回复
对,要大写S,否则ie下正常而firefox下不正常。

ie 7 以下吧
dalmeeme 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ds252743641 的回复:]
readyState
中的S为大写
[/Quote]
对,要大写S,否则ie下正常而firefox下不正常。
ds252743641 2010-11-30
  • 打赏
  • 举报
回复
readyState
中的S为大写

ds252743641 2010-11-30
  • 打赏
  • 举报
回复
alert(xmlhttp.readystate);

改为
alert(xmlhttp.readyState);
wuyq11 2010-11-30
  • 打赏
  • 举报
回复
var xmlHttp = false;
try {
xmlHttp = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xmlHttp = false;
}
}
}
if (!xmlHttp) {alert("启用Ajax功能失败,您可能无法使用本站的部分功能!");}


....xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
}
}
function ShowResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var s;
s=xmlHttp.responseText;
alert(s);
}
}
}
dalmeeme 2010-11-30
  • 打赏
  • 举报
回复
callback()方法内xmlhttp对象没定义啊,要么做成参数传进来,要么设为全局变量。
生活的信仰 2010-11-30
  • 打赏
  • 举报
回复
只能这执行到这个函数 alert(xmlhttp.readystate);

提示未定义为什么啊

function callback()
{
alert("callback");

alert(xmlhttp.readystate);
if(xmlhttp.readystate ==4)
{
alert("rr");
if(xmlhttp.status ==200)
{
alert("gggg");
var nn = xmlhttp.responseText;
alert(nn);
}
}
}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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