【发布时间】:2010-09-29 02:12:46
【问题描述】:
我在使用 XMLHttpRequest 下载渐进式数据时遇到问题。我得到一个状态 2 而不是状态 3。在状态 3 之后它再也不会被调用。我究竟做错了什么?我在需要刷新数据的地方读到了,但我该怎么做?
这是我的代码:
var xmlHttp = new XMLHttpRequest();
// try to connect to the server
try
{
// initiate server request
xmlHttp.open("GET", "http://208.43.121.133:8164/;", true);
xmlHttp.setRequestHeader("Icy-Metadata", "1");
xmlHttp.onreadystatechange = function()
{
alert("status: "+xmlHttp.status);
alert("State: "+xmlHttp.readyState);
if (xmlHttp.readyState == 3)
{
alert(xmlHttp.responseText);
}
};
xmlHttp.send(null);
}
// display an error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
readyState 为 3 时是否允许读取 xmlHttp.responseText?
【问题讨论】: