1.
XMLHttpRequest(不要问了,Ajax的核心组件)
function ajax_function(var1,var2){
var xmlHttp = null;
function ajax_function(var1,var2){
try
{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e) {
try
{
xmlHttp=new ActiveXObject('Msxml2.XMLHTTP'); // Internet Explorer
}
catch (e){
try{xmlHttp=new ActiveXObject(' Microsoft.XMLHTTP ');}
catch (e){
alert('Your browser does not support AJAX!');
return false;
}
}
}
2.XML的使用
// var xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" ); // ie5.5+,CreateObject("Microsoft.XMLDOM")
/ var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- loadXML = function(xmlFile)
- {
- var xmlDoc;
- if(window.ActiveXObject)
- {
- xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
- xmlDoc.async = false;
- xmlDoc.load(xmlFile);
- }
- else if (document.implementation&&document.implementation.createDocument) /// Firefox 及其他浏览器的 XML 解析器
- {
- xmlDoc = document.implementation.createDocument('', '', null);
- xmlDoc.load(xmlFile);
- }
- else
- {
- return null;
- } return xmlDoc;
- }
其他浏览器中的加载: parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml");
3.