responsebody text html,responseBody

functionCreateHTTPRequestObject () {// although IE supports the XMLHttpRequest object, but it does not work on local files.varforceActiveX = (window.ActiveXObject&&location.protocol==="file:");if(window.XMLHttpRequest&& !forceActiveX) {returnnewXMLHttpRequest();

}else{try{returnnewActiveXObject("Microsoft.XMLHTTP");

}catch(e) {}

}alert("Your browser doesn't support XML handling!");returnnull;

}functionCreateMSXMLDocumentObject () {if(typeof(ActiveXObject) !="undefined") {varprogIDs = ["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument"];for(vari =0; i < progIDs.length; i++) {try{returnnewActiveXObject(progIDs[i]);

}catch(e) {};

}

}returnnull;

}functionCreateXMLDocumentObject (rootName) {if(!rootName) {

rootName ="";

}varxmlDoc = CreateMSXMLDocumentObject ();if(xmlDoc) {if(rootName) {varrootNode = xmlDoc.createElement(rootName);

xmlDoc.appendChild(rootNode);

}

}else{if(document.implementation.createDocument) {

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

}

}returnxmlDoc;

}functionParseHTTPResponse (httpRequest) {varxmlDoc = httpRequest.responseXML;// if responseXML is not valid, try to create the XML document from the responseText propertyif(!xmlDoc || !xmlDoc.documentElement) {if(window.DOMParser) {varparser =newDOMParser();try{

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

}catch(e) {alert("XML parsing error");returnnull;

};

}else{

xmlDoc = CreateMSXMLDocumentObject ();if(!xmlDoc) {returnnull;

}

xmlDoc.loadXML(httpRequest.responseText);

}

}// if there was an error while parsing the XML documentvarerrorMsg =null;if(xmlDoc.parseError&& xmlDoc.parseError.errorCode!=0) {

errorMsg ="XML Parsing Error: "+ xmlDoc.parseError.reason+" at line "+ xmlDoc.parseError.line+" at position "+ xmlDoc.parseError.linepos;

}else{if(xmlDoc.documentElement) {if(xmlDoc.documentElement.nodeName=="parsererror") {

errorMsg = xmlDoc.documentElement.childNodes[0].nodeValue;

}

}

}if(errorMsg) {alert(errorMsg);returnnull;

}// ok, the XML document is validreturnxmlDoc;

}// returns whether the HTTP request was successfulfunctionIsRequestSuccessful (httpRequest) {// IE: sometimes 1223 instead of 204varsuccess = (httpRequest.status==0||

(httpRequest.status>=200&& httpRequest.status<300) ||

httpRequest.status==304|| httpRequest.status==1223);returnsuccess;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值