首页WEB开发Ajax教程 → XMLHttpRequest对象

XMLHttpRequest对象

日期:2007-4-15 15:13:23 出处:其他转载 作者:不详 人气:

Ajax应用的第一个步骤,就是创建XMLHttpRequest对象,本函数为你解决IE和非IE浏览器下创建XMLHttpRequest对象的问题。本函数创建了名为“xmlHttp”的XMLHttpRequest对象,在你的应用当中,把现在下来的文件包含到你的网页中,就可以直接使用它了。

xmlHttpRequest.js

/* 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;
}

关于本站 | 帮 助 | 广告服务 | 版权声明 | 业务合作 | 捐助本站 | 软件发布 | 联系我们
77资源下载 www.77zy.com ©2007-2008 版权所有
备案编号:赣ICP备07002641号  QQ:674648476