AJAX响应- XmlHttp.responseXML被切断

AJAX response - XmlHttp.responseXML is cut off

本文关键字:responseXML XmlHttp 响应 AJAX      更新时间:2023-09-26

当为AJAX请求返回的responseXML在中间被切断时,我们遇到了一种奇怪的行为。我们正在检查readyState(对于4)和XmlHttp。状态(为200),然后才继续解析responseXML。

相关代码如下:

. 
. 
. 
if ((myCommunicator != null) && (myCommunicator.XmlHttp.readyState == 4)) 
{ 
    myCommunicator.OnDataAvailable(); 
}

OnDataAvailable功能:

SoapCommunicator.OnDataAvailable = function () {   
DebugWrite("OnDataAvailable");   
XMLResponse = this.XmlHttp.responseXML;
if (this.XmlHttp.status != 200)
{
    DebugWrite("XmlHttp.status " + this.XmlHttp.status);
    DebugWrite("XmlHttp.statusText " + this.XmlHttp.statusText);
    DebugWrite("XmlHttp.readyState " + this.XmlHttp.readyState);
}
//  DebugWrite("xml=" + XMLResponse.xml.replace(/'r'n/g, ""));
if (XMLResponse.xml.length > 0)
{
    if (0 == XMLResponse.parseError.errorCode)
    {
        var dataNode = XMLResponse.lastChild.firstChild.firstChild.firstChild;
    }
    else
    {
        throw "Failed to parse SOAP response";
    }
}
else
{
    var result = new Object();
    result.IsSuccessful = false;
    result.ErrorDescription = "Failed to connect to server.";
    result.ErrorCode = failedToConnectToServer;
    eval(this.ResultCallBack + "(result)");
} }

在本例中,dataNode保存信息。当我们把它写到对数的时候我们看到有时候它会在中间被截断。只有在大量数据时才会注意到这种行为。关于它的另一件事是它总是在不同的部分被切断,而不是在精确的X字节之后。

顺便说一下,发生这种情况的客户是使用德语编码的。

谢谢!

更新:我忘记提到的另一件事是,一旦我们试图解析数据(在readyState == 4和XmlHttp之后)。状态= 200)我们得到这个错误:

ERROR: Message='完成此操作所需的数据不存在还可以'

假设您使用的是ASP。. NET Web服务的后端(ASMX) -尝试将这一行添加到Web。配置文件(到节):

<httpRuntime maxRequestLength="2147483647" />

我有一个类似的问题,XmlHttpRequest响应被切断,有时。

我不知道这是否是你的问题的原因,但这可以帮助别人与这种问题。我的问题显然是由于响应中有一些Unicode字符引起的。

由于Unicode字符的原因,当我在服务器上设置内容长度报头字段时,我实际上设置得太低了。当浏览器获得响应时,它只读取与内容长度标头指定的相同的字节数,由于我的错误,该标头指示响应中字符的数量,而不是字节数。

我在Node.js上使用String:length来计算内容长度的值。显然,返回的是字符数,而不是字节数。

我通过注释掉在服务器上设置内容长度头的代码部分来解决这个问题。