怎么我写的ajax请求的readyState总是为0(在线等)

wt495861533 2011-10-08 04:35:52
function GetXmlHttpObject(){
var xmlHttp = null;
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function showMsg(title,pid,_marker){
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null){
alert ("you browser don't support the ajax");
return;
}
var url = "http://localHost:8080/pm/pstatus_getStatus.action"
xmlHttp.onreadystatechange = stateChanged(title,pid,_marker);
xmlHttp.open("GET", url, true);
xmlHttp.send();
alert("ok");
}
function stateChanged(title,pid,_marker){
alert(xmlHttp.readyState);
if(xmlHttp.readyState==4){
var json = xmlHttp.responseText;
alert(json);
var _iw = createInfoWindow(json);
_marker.openInfoWindow(_iw);
_iw.addEventListener("open",function(){
_marker.getLabel().hide();
})
_iw.addEventListener("close",function(){
_marker.getLabel().show();
})
_marker.getLabel().addEventListener("click",function(){
_marker.openInfoWindow(_iw);
})
}
alert(xmlHttp.readyState);
}
...全文
201 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
BLUE_LG 2011-10-08
  • 打赏
  • 举报
回复
我还以为楼主是因为本地的缘故。。。
wt495861533 2011-10-08
  • 打赏
  • 举报
回复
额 原来如此啊 太感谢了
Go 旅城通票 2011-10-08
  • 打赏
  • 举报
回复
。。。
xmlHttp.onreadystatechange = stateChanged(title,pid,_marker);错了。。你这样相当于执行stateChanged,然后将stateChanged的返回值作为状态转换函数。。,stateChanged没有返回,状态转换为空。

xmlHttp.onreadystatechange =function(){ stateChanged(title,pid,_marker);};/////这样。。


你输出的json结构也是错的,字符串要用""或者''括起来
this.getResponse().getWriter().write(
"{title:\"国家大剧院\",name:\"国家大剧院\",use:12,free:2}");


wt495861533 2011-10-08
  • 打赏
  • 举报
回复
后台是这样写的

public String getStatus() {
this.getResponse().setContentType("text/html;charset=utf-8");
try {
this.getResponse().getWriter().write(
"{title:国家大剧院,name:国家大剧院,use:12,free:2}");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

52,797

社区成员

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

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