设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 223|回复: 0

Ajax: responseXML in Internet Explorer fails

[复制链接]
发表于 2013-10-31 23:35:58 | 显示全部楼层 |阅读模式
I'm requesting a xml file in javascript from a xmlhttprequest object:
requester.responseXML

It runs ok in firefox, but in IE it returns null. (requester.resonseText run ok).

Searching in google I found this solution:
http://forum.java.sun.com/thread ... 6590&tstart=105
  1. /Just to check if it is a different navigator from internet explorer
  2. if (document.implementation && document.implementation.createDocument){
  3. xmlDoc = requester.responseXML;
  4. //In case to be the internet explorer
  5. } else if (window.ActiveXObject){
  6. //Create a xml tag in run time
  7. var testandoAppend = document.createElement('xml');
  8. //Put the requester.responseText in the innerHTML of the xml tag
  9. testandoAppend.setAttribute('innerHTML',requester.responseText);
  10. //Set the xml tag's id to _formjAjaxRetornoXML
  11. testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
  12. //Add the created tag to the page context
  13. document.body.appendChild(testandoAppend);
  14. //Just for check put the xmlhttp.responseXML in the innerHTML of the tag
  15. document.getElementById('_formjAjaxRetornoXML').innerHTML = requester.responseText;
  16. //Now we can get the xml tag and put it on a var
  17. xmlDoc = document.getElementById('_formjAjaxRetornoXML');
  18. //So we have a valid xml we can remove the xml tag document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));\n" +
  19. }
  20. else{
  21. //If the browser doesnt support xml
  22. alert('Your browser can\\'t handle this script');
  23. }
复制代码
if you are running via file:// protocol, it could be as easy as:
  1. var result = xmlhttp.responseXML;
  2. if (!result.documentElement && xmlhttp.responseStream) {
  3. result.load(xmlhttp.responseStream);
  4. }

  5. // work with your result XMLDocument
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2025-8-25 21:05 , Processed in 0.015448 second(s), 20 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表