AJAXLib v. 1.0

// AJAXLib v. 1.0
// author: Jacek Karaszewski, http://www.karaszewski.com/tools/ajaxlib/
// licenced under Creative Commons Attribution 2.5 License

// public

// function loadXMLDoc(xml_url, function_name, ignore_white)
function loadXMLDoc(url, callFunc, ignoreWhite) {
 functionToCall = callFunc;
 stripWS = ignoreWhite;
 xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")
 xmlRequestObj.onreadystatechange = proccessXML;
 xmlRequestObj.open("GET", url, true);
 xmlRequestObj.send(null);
}


// private

function is_ws(nod) {
 return !(/[^\t\n\r ]/.test(nod.data));
}

function findWhiteSpace(node, nodeNo) {
 for (i=0; i<node.childNodes.length; i++) {
  if (node.childNodes[i].nodeType == 3 && is_ws(node.childNodes[i])) {
   nodesToDelete[nodesToDelete.length] = node.childNodes[i]
  }
  if (node.childNodes[i].hasChildNodes()) {
   findWhiteSpace(node.childNodes[i], i);
  }
 }
 node = node.parentNode;
 i = nodeNo;
}

function stripWhiteSpace(node) {
 nodesToDelete = Array();
 findWhiteSpace(node, 0);
 for(i=nodesToDelete.length-1;i>=0;i--) {
  nodeRef = nodesToDelete[i];
  nodeRef.parentNode.removeChild(nodeRef)
 }
}

function proccessXML() {
 if (xmlRequestObj.readyState == 4 && (xmlRequestObj.status == 200 || xmlRequestObj.status == 304)) {
  if(stripWS) {
   stripWhiteSpace(xmlRequestObj.responseXML);
  }
  resultXML = xmlRequestObj.responseXML;
  functionToCall()
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值