可以使用xmlhttp=new XMLHttpRequest();
代替: var domDoc = new ActiveXObject("Microsoft.XMLDOM");
。 適用於其他瀏覽器(Firefox,Chrome,Opera,Safari)。
並加載XML文件,請使用:
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
如下鏈接心滿意足的..
http://www.w3schools.com/xml/xml_dom.asp
請試試這個以及..
var xmlDictionary = null;
function onGridMembersSelection(id,xml) {
// code for IE
if (window.ActiveXObject || xhttp.responseType=="msxml-document")
{
var domDoc = new ActiveXObject("Microsoft.XMLDOM");
domDoc.loadXML(xml);
var helpHtml2 = "";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "Dictionary.xml", true);
xmlDictionary = xmlhttp.responseXML;
xmlhttp.send();
helpHtml2 += xmlDictionary.selectSingleNode("Terms/Term[Key='" + domDoc.selectSingleNode("Members/Member/@UName").text + "']/Desc").text;
alert(helpHtml2);
}
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var domDoc=new XMLHttpRequest();
xmlhttp.open("GET", "Dictionary.xml", true);
xmlDictionary = xmlhttp.responseXML;
xmlhttp.send();
xml.evaluate("Terms/Term[Key='" +xml.evaluate("Members/Member/@UName", xmlDictionary , null, XPathResult.ANY_TYPE, null), xmlDictionary , null, XPathResult.ANY_TYPE, null).nodeValue;
helpHtml2 += .text;
alert(helpHtml2);
}
}
這似乎有用:http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp – endofsource