Ajax笔记

1,创建XMLHttpRequest对象

xmlhttp=newXMLHttpRequest();--IE7+,Firefox,Chrome,Safari,andOpera

xmlhttp=newActiveXObject("Microsoft.XMLHTTP");--IE5,IE6

2,将XML文本解析为xmldoc对象:

InternetExplorerusestheloadXML()methodtoparseanXMLstring,whileotherbrowsersusetheDOMParserobject.

if(window.DOMParser)//firefox

{

parser=newDOMParser();

xmlDoc=parser.parseFromString(txt,"text/xml");

}

else//InternetExplorer

{

xmlDoc=newActiveXObject("Microsoft.XMLDOM");

xmlDoc.async=false;

xmlDoc.loadXML(txt);

}

读取XML文件为xmldoc对象:

if(window.DOMParser)//firefox

{

xmlDoc=document.implementation.createDocument("","",null);

xmlDoc.async="false";

xmlDoc.load("xxx.xml");

}

else//InternetExplorer

{

xmlDoc=newActiveXObject("Microsoft.XMLDOM");

xmlDoc.async="false";

xmlDoc.load("xxx.xml");

}

相关推荐