天气预报webservice地址:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
在控制台执行:
var xmlhttp;
xmlhttp=null;
var url="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince";
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Content-Type","text/html; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction","http://webservice.webxml.com.cn/WebServices");
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
console.log(xmlhttp.responseText);
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusText);
}
}
}
控制台运行结果:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
<string>黑龙江,3113</string>
<string>吉林,3114</string>
<string>辽宁,3115</string>
<string>内蒙古,3116</string>
<string>河北,3117</string>
<string>河南,3118</string>
<string>山东,3119</string>
<string>山西,31110</string>
<string>江苏,31111</string>
<string>安徽,31112</string>
<string>陕西,31113</string>
<string>宁夏,31114</string>
<string>甘肃,31115</string>
<string>青海,31116</string>
<string>湖北,31117</string>
<string>湖南,31118</string>
<string>浙江,31119</string>
<string>江西,31120</string>
<string>福建,31121</string>
<string>贵州,31122</string>
<string>四川,31123</string>
<string>广东,31124</string>
<string>广西,31125</string>
<string>云南,31126</string>
<string>海南,31127</string>
<string>新疆,31128</string>
<string>西藏,31129</string>
<string>台湾,31130</string>
<string>北京,311101</string>
<string>上海,311102</string>
<string>天津,311103</string>
<string>重庆,311104</string>
<string>香港,311201</string>
<string>澳门,311202</string>
<string>钓鱼岛,311203</string>
</ArrayOfString>
参考链接:http://hi.baidu.com/yanguang1670/item/2928b2a7a6ebf7db5bf191df
var xmlhttp; xmlhttp=null; var url="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince"; if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",url,true); xmlhttp.setRequestHeader("Content-Type","text/html; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction","http://webservice.webxml.com.cn/WebServices"); xmlhttp.send(null); } else { alert("Your browser does not support XMLHTTP."); } function state_Change() { if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = "OK" console.log(xmlhttp.responseText); } else { alert("Problem retrieving XML data:" + xmlhttp.statusText); } } }