AJAX response - XmlHttp.responseXML is cut off

2019-07-12 18:49发布

问题:

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'

回答1:

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" />