Created
September 11, 2014 09:35
-
-
Save ghostzhang/8cf9cd79abad75599e2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xmlHttp; | |
//创建对象 | |
function createXMLHttpRequest(){ | |
if (window.ActiveXObject){ | |
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
}else if (window.XMLHttpRequest){ | |
xmlHttp = new XMLHttpRequest("Msxml2.XMLHTTP.3.0"); | |
} | |
} | |
//发请请求 | |
function doSearch(url){ | |
createXMLHttpRequest(); | |
xmlHttp.onreadystatechange = handleStateChange; | |
xmlHttp.open("GET",url,"true"); | |
xmlHttp.send(null); | |
} | |
//处理响应 | |
function handleStateChange(){ | |
if (xmlHttp.readyState == 4){ | |
if (xmlHttp.status == 200){ | |
parseResults(); | |
} | |
} | |
} | |
//取得URL | |
function createURL(text){ | |
var url; | |
url = "BranchAreaInfo.asp?AreaID="; | |
if (text != ""){ | |
url += escape(text); | |
doSearch(url); | |
} | |
} | |
//读取XML文件 | |
function parseResults(){ | |
var results = xmlHttp.responseXML; | |
var sDiv = ""; | |
var shop = "null"; | |
var name =""; | |
var address = ""; | |
var phone = ""; | |
var fax = ""; | |
var hhitshop = results.getElementsByTagName("shop"); | |
for (var i = 0; i< hhitshop.length; i++){ | |
shop = hhitshop[i]; | |
name = shop.getElementsByTagName("name")[0].firstChild.nodeValue; | |
phone = shop.getElementsByTagName("phone")[0].firstChild.nodeValue; | |
fax = shop.getElementsByTagName("fax")[0].firstChild.nodeValue; | |
address = shop.getElementsByTagName("address")[0].firstChild.nodeValue; | |
sDiv += addDiv(name,photo,address,phone,fax); | |
} | |
document.getElementById("results").innerHTML = sDiv; | |
} | |
//输出格式化 | |
function addDiv(name,photo,address,phone,fax){ | |
var WDiv = "<div class='shop_list'>"; | |
WDiv += "<a href='#'><img alt='"+ name +"' src='"+ photo +"' /></a>"; | |
WDiv += "<dl>"; | |
WDiv += "<dt><a href='#'>名称</a></dt>"; | |
WDiv += "<dd>电话:"+ phone +"</dd>"; | |
WDiv += "<dd>传真:"+ fax +"</dd>"; | |
WDiv += "<dd>地址:"+ address +"</dd>"; | |
WDiv += "</dl>"; | |
WDiv += "</div>"; | |
return WDiv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment