使用原始Javascript加载XML
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用原始Javascript加载XML相关的知识,希望对你有一定的参考价值。
/* Author: Alvin Crespo Description: XMLLoader */ //xml object variable var xmlhttp; function loadXMLDoc(dname,type){ //get the proper xml object (based on browser of user) xmlhttp = GetXMLHTTPObject(); //if no object was found, tell the user that their browser is not supported if (xmlhttp==null){ alert ("Your browser is not supported!"); return; //break the current function loadXMLDoc } //keep track of the state xmlhttp.onreadystatechange = function(){ //finishing state if (xmlhttp.readyState==4){ //successful codes: 200 for webserver and 0 for local if (xmlhttp.status == 200 || xmlhttp.status == 0){ //process code here if(type == "contact-cards") createContactCards(xmlhttp.responseXML); //located at contactcards.js if(type == "contact-profile") createProfile(xmlhttp.responseXML); //located at profiles.js } //let the user know that there was an error loading the xml document else{ //should handle the error better alert("Error Loading XML"); } } } //get the document and keep track of what is happening in a queue by setting asynch to true xmlhttp.open("GET",dname,true); xmlhttp.send(""); } //get the proper xml object function GetXMLHTTPObject(){ if (window.XMLHttpRequest){ // for all browsers besides ie 5 and 6 and perhaps 7 return new XMLHttpRequest(); }else if (window.ActiveXObject){ // catch ie 5/6/7 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } //END OF XML LOADING
以上是关于使用原始Javascript加载XML的主要内容,如果未能解决你的问题,请参考以下文章
React 路由器在 url 地址栏重新加载时提供 javascript 对象而不是原始类型
带有 Javascript 的 WebView 不断重新加载
在Javascript事件链中,浏览器的“返回原始位置”在刷新后会发生什么?