日期:2014-05-17 浏览次数:20834 次
function getXmlHttpPrefix() { if (getXmlHttpPrefix.prefix) return getXmlHttpPrefix.prefix; var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; var o; for (var i = 0; i < prefixes.length; i++) { try { // try to create the objects o = new ActiveXObject(prefixes[i] + ".XmlHttp"); return getXmlHttpPrefix.prefix = prefixes[i]; } catch (ex) {}; } throw new Error("Could not find an installed XML parser"); } ////////////////////////// // Start the Real stuff // ////////////////////////// // XmlHttp factory function XmlHttp() {} XmlHttp.create = function () { try { if (window.ActiveXObject) { return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp"); } else if (window.XMLHttpRequest) { var req = new XMLHttpRequest(); //some versions of Moz do not support the readyState property //and the onreadystate event so we patch it! if (req.readyState == null) { req.readyState = 1; req.addEventListener("load", function () { req.readyState = 4; if (typeof req.onreadystatechange == "function") req.onreadystatechange(); }, false); } return req; } } catch (ex) { throw new Error("Your browser does not support XmlHttp objects"); } } function _startLoadXmlTree(url) { var xmlHttp = XmlHttp.create(); if (xmlHttp.overrideMimeType){ xmlHttp.overrideMimeType("text/xml; charset=UTF-8"); } xmlHttp.open("GET", sSrc, true); // async xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4) { alert(xmlHttp.responseText); //可以取得xml的内容????????????? alert(xmlhttp.responseXML.documentElement); //为空??????????? } }; // call in new thread to allow ui to update window.setTimeout(function () { xmlHttp.send(null); }, 10); }
<?xml version="1.0" encoding="UTF-8"?> <tree> <tree text="MH" src="GuideList/MH.xml"/> <tree text="MR" src="GuideList/MR.xml"/> <tree text="a.swf" action="JavaScript:Play('player.html?file=file:///D:/Test/Guides/Flash/a.swf')"/> <tree text="cc.swf" action="JavaScript:Play('player.html?file=file:///D:/Test/Guides/Flash/cc.swf')"/> <tree text="movie_name.swf" action="JavaScript:Play('player.html?file=file:///D:/Test/Guides/Flash/movie_name.swf')"/> </tree>