【问题标题】:ajaForm returns invalid XML in responseXMLajaForm 在 responseXML 中返回无效的 XML
【发布时间】:2013-09-22 08:16:51
【问题描述】:

我正在使用 IE9 和 jquery-1.8.0.js。我在 responseXML 中得到了额外的垃圾字符。服务器实际发送的XML如下,

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

但是当我检查 responseText 时,它显示如下,这是 loadXML 出错。注意空格和 \r\n- 添加了不需要的字符,

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

下面是代码sn-p,

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

我想知道是谁在自动更改 XML。感谢您提供解决此问题的指导。

谢谢, jdp

【问题讨论】:

    标签: javascript html xml ajaxform


    【解决方案1】:

    我不知道谁在中间篡改 XML 的确切原因,但我使用下面的函数来清理 XML 并解决了我的问题。

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

    如果有任何好的解决方案,请欣赏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-08
      • 2017-05-16
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      相关资源
      最近更新 更多