首页 > Web开发 > 详细

怎样获取从服务器返回的xml或html文档对象

时间:2019-09-20 13:33:51      阅读:86      评论:0      收藏:0      [点我收藏+]

使用 xhr.responseXML; 

通过这个属性正常获取XML或HTML文档对象有两个前置条件: 

1. Content-Type头信息的值等于: text/xml 或 application/xml

2. xhr.responseType 需要赋值为: "document"

var xhr = new XMLHttpRequest();
xhr.open(‘GET‘, ‘/server‘, true);

xhr.responseType = ‘document‘;
xhr.overrideMimeType(‘text/xml‘);

xhr.onload = function () {
  if (xhr.readyState === 4 && xhr.status === 200) {
    console.log(xhr.responseXML);
  }
};

xhr.send(null);

 

注意: 如果Content-Type不等于 text/xml 或 application/xml, 那需要通过xhr.overrideMimeType(‘text/xml‘) 强制进行XML解析.

 

怎样获取从服务器返回的xml或html文档对象

原文:https://www.cnblogs.com/aisowe/p/11555916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!