Ajax应用的第一个步骤,就是创建XMLHttpRequest对象,本函数为你解决IE和非IE浏览器下创建XMLHttpRequest对象的问题。本函数创建了名为“xmlHttp”的XMLHttpRequest对象,在你的应用当中,把现在下来的文件包含到你的网页中,就可以直接使用它了。
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function countElements(node){
var counter=0;
if(node.nodeType == 1){
counter++;
}
var childs=node.childNodes;
for(var i=0;i<childs.length;i++){
counter += countElements(childs[i]);
}
return counter;
}