Ajax 请求和 text/xml

发布于 2024-07-16 15:39:01 字数 137 浏览 6 评论 0原文

我通过 ajax 请求 xml 文件,服务器使用 header text/xml 作为返回的数据。 Firefox 读取此标头并将数据转换为 XMLDocument 对象,这意味着我无法将其与 jQuery 一起使用。 如何获取纯文本形式的 XML 文档?

I am requesting and xml file over ajax, the server uses the header text/xml for the data returned. Firefox reads this header and turns the data into an XMLDocument object which means I can't use it with jQuery. How can I get my XML document as plain text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疾风者 2024-07-23 15:39:01

返回的xmlHttp对象有一个responseXML属性。 这映射到 XmlDocument。 如果您阅读本文档子节点的 textContent,您将能够检索纯文本响应。

例如:

// Works on FF. For IE, you can read the lastChild.text property.
var responseText = xmlHttp.responseXML.lastChild.textContent;

或者,您可以访问responseText属性以获取字符串形式的整个响应:

// Works on both IE and FF.
var responseText = xmlHttp.responseText;

The xmlHttp object returned has a responseXML property. This maps to an XmlDocument. If you read the textContent of the childnodes of this document, you will be able to retrieve the plain text response.

For instance:

// Works on FF. For IE, you can read the lastChild.text property.
var responseText = xmlHttp.responseXML.lastChild.textContent;

Alternatively, you can access the responseText property to get the entire response as a string:

// Works on both IE and FF.
var responseText = xmlHttp.responseText;
亚希 2024-07-23 15:39:01

通过序列化修复它:

var serializer = new XMLSerializer();
var text = serializer.serializeToString(xmldoc);

Fixed it by serializing:

var serializer = new XMLSerializer();
var text = serializer.serializeToString(xmldoc);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文