Ajax响应 - XmlHttp.responseXML被切断 [英] AJAX response - XmlHttp.responseXML is cut off

查看:106
本文介绍了Ajax响应 - XmlHttp.responseXML被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正遭遇时正在被返回的AJAX请求的responseXML在中间切断奇怪的行为。我们检查两个readyState的(4)和XmlHttp.status(为200),然后才进行到解析的responseXML。

下面是相关code:

 。
。
。
如果((myCommunicator = NULL)及!及(myCommunicator.XmlHttp.readyState == 4))
{
    myCommunicator.OnDataAvailable();
}
 

OnDataAvailable功能:

  SoapCommunicator.OnDataAvailable =功能(){
DebugWrite(OnDataAvailable);
XMLResponse = this.XmlHttp.responseXML;

如果(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 /克,));
如果(XMLResponse.xml.length大于0)
{
    如果(0 == XMLResponse.parseError.error code)
    {
        VAR的Datanode = XMLResponse.lastChild.firstChild.firstChild.firstChild;
    }
    其他
    {
        抛出无法解析SOAP响应;
    }
}
其他
{
    VAR的结果=新的对象();
    result.IsSuccessful = FALSE;
    result.ErrorDescription =无法连接到服务器。
    result.Error code = failedToConnectToServer;
    的eval(this.ResultCallBack +(结果));
}}
 

在这个例子中,数据节点所保存的信息。当写入到日志中,我们看到,有时它得到中间切断。这种行为被发现只对大量的数据。另外一个关于它的事情是,它总是纠缠在不同的部位切断,并经过精确的X字节没有。

顺便说一句,这发生这种情况,客户是德国的编码。

谢谢!

更新: 另一件事,我忘了提的是,一旦我们试图分析数据我们得到这个错误(readyState的== 4和XmlHttp.status = 200后):

  

错误:消息='的必要,完成此操作的数据不   尚未公布

解决方案

假设你使用ASP.NET Web服务在后端(ASMX) - 尝试添加​​此行到web.config文件(部分):

 <的httpRuntime maxRequestLength的=2147483647/>
 

We are encountering a strange behavior when the responseXML which is being returned for an AJAX request is cut off in the middle. We are checking the both the readyState (for 4) and the XmlHttp.status (for 200) and only then proceeding to parse the responseXML.

Here is the relevant code:

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

OnDataAvailable function:

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)");
} }

In this example the dataNode holds the information. When writing it to the log we are seeing that sometimes it get cut off in the middle. This behavior was noticed only for large amount of data. One other thing about it is that it always got cut off in different parts, and not after exact X bytes.

BTW, the customer which this happens to is on German encoding.

Thanks!

Update: Another thing that I forgot to mention is that once we're trying to parse the data (after readyState == 4 and XmlHttp.status = 200) we're getting this error:

ERROR: Message='The data necessary to complete this operation is not yet available'

解决方案

Assuming you're using ASP.NET Web Services on the backend (ASMX) - try adding this line to the web.config file (to the section):

<httpRuntime maxRequestLength="2147483647" />

这篇关于Ajax响应 - XmlHttp.responseXML被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆