Loading documents:/*@desc 加载XHR文件@author lee [<[email protected]>]@param file 文件路径@param async 同步或异步 true 异步 flase 同步@return xmlDoc 加载后的内容*/function loadDoc(file,async=true){if(window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();}else{ // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.open("GET",file,async);xmlhttp.send();xmlDoc=xmlhttp.responseXML;return xmlDoc}
Load string:/*@desc 加载XML文档@author lee [<[email protected]>]@param txt 字符串@param async 同步或异步 true 同步 flase 异步@return xmlDoc 加载后的DOM对象*/function loadStr(txt,async=true){if(window.DOMParser){ parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml");}else{ // Internet Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=async; xmlDoc.loadXML(txt);}return xmlDoc}
Encapsulation of JavaScript XHR objects (cross-browser)