0

I am using IE9 and jquery-1.8.0.js. I am getting extra junk character in responseXML. The actual XML sent by server is as below,

<?xml version="1.0" encoding="UTF-8" ?><ResponseStatus><version>0.0.1</version><requestURL>myurl.com</requestURL><statusCode>-1</statusCode><statusString>success</statusString></ResponseStatus>

But when I check responseText it shows as below which is giving error with loadXML. Notice the spaces and \r\n- characters added unneeded,

"  <?xml version=\"1.0\" encoding=\"UTF-8\" ?> \r\n- <ResponseStatus>\r\n  <version>0.0.1</version> \r\n  <requestURL>myurl.com</requestURL> \r\n  <statusCode>-1</statusCode> \r\n  <statusString>success</statusString> \r\n  </ResponseStatus>"

below is the code snippet,

var options = 
{
    beforeSend:...
    error:...
    success: function (responseXML, statusText, xhr, $form)
             {
                var xmlobj = responseXML.documentElement.innerText;
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(xmlobj);
                //xmlDoc.parseError.errorCode = -1072896682
                //xmldoc.reason = "Invalid at the top level of the document.\r\n"
             }
};

I am wondering who is changing the XML automatically. I appreciate your guidance resolving this.

Thanks, Jdp

4

1 回答 1

0

I don't know the exact reason about who is tampering the XML in between but I used below function to sanitize the XML and resolved my problem.

function sanitizeXML(xmlobj)
{
    "use strict";
    return xmlobj.replace("\r\n-","");
}

Appreciate if there is any good solution.

于 2013-09-17T23:36:27.540 回答