2

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
    Really "middle" or "near the end"? Do you have any non-ASCII characters in the data? I've seen HTTP responses cut off because their `Content-Length` header was calculated on *number of characters* instead of *number of bytes* (and some characters take up multiple bytes). – Quentin Feb 28 '13 at 11:55
  • @Quentin Thanks for your help. I'm sending the request to C# web-service, do you refer to the request Content-Length or the response Content-Length? Currently I'm not setting the Content-Length in my request at all. and how can I set the Content-Length of the response? –  Feb 28 '13 at 12:20
  • The response content-length (it is the response that is being cut off). No idea how you set it, I don't do C# and I don't know how your system is set up. – Quentin Feb 28 '13 at 12:22
  • @Quentin But the problem is that I get the same response and every time it is being cut in a different place. Well maybe not every time but sometimes. –  Feb 28 '13 at 12:35

2 Answers2

0

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" />
Shay Friedman
  • 4,808
  • 5
  • 35
  • 51
0

I had a similar problem, XmlHttpRequest response was cut off, sometimes.

I don't know if this is the cause of your problem but this could help someone with this kind of issue. My problem was apparently caused by having some Unicode characters in the response.

It appears that because of the Unicode characters, when I set the content-length header-field on the server I actually set it too low. When the browser got the response it only read in as many bytes as was specified by the content-length header, which, because of my error, indicated the number of characters, not number of bytes, in the response.

I was using String:length on Node.js to calculate the value for the content-length. Apparently that returns the number of characters, not number of bytes.

I got rid of the problem by commenting out the part of my code that set the content-length header on the server. Now it works fine.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Panu Logic
  • 2,193
  • 1
  • 17
  • 21