|
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- /Just to check if it is a different navigator from internet explorer
- if (document.implementation && document.implementation.createDocument){
- xmlDoc = requester.responseXML;
- //In case to be the internet explorer
- } else if (window.ActiveXObject){
- //Create a xml tag in run time
- var testandoAppend = document.createElement('xml');
- //Put the requester.responseText in the innerHTML of the xml tag
- testandoAppend.setAttribute('innerHTML',requester.responseText);
- //Set the xml tag's id to _formjAjaxRetornoXML
- testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
- //Add the created tag to the page context
- document.body.appendChild(testandoAppend);
- //Just for check put the xmlhttp.responseXML in the innerHTML of the tag
- document.getElementById('_formjAjaxRetornoXML').innerHTML = requester.responseText;
- //Now we can get the xml tag and put it on a var
- xmlDoc = document.getElementById('_formjAjaxRetornoXML');
- //So we have a valid xml we can remove the xml tag document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));\n" +
- }
- else{
- //If the browser doesnt support xml
- alert('Your browser can\\'t handle this script');
- }
复制代码 if you are running via file:// protocol, it could be as easy as:- var result = xmlhttp.responseXML;
- if (!result.documentElement && xmlhttp.responseStream) {
- result.load(xmlhttp.responseStream);
- }
- // work with your result XMLDocument
复制代码
|
|