我正在尝试使用 wsf.cdyne.com/WeatherWS/Weather.asmx 提供的天气 Web 服务。我确信我可以通过使用 uri "' http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP?ZIP= ' + zipcode" 获得 XML 格式的响应。
所以我现在要做的是使用 XmlHttpRequest 发送上面的 uri。我添加了一些警报来监控状态。在 open() 之后,readyState 为 1。之后我无法得到任何其他响应。如果我删除语句“xmlHttpRequest.onreadystatechange = processRequest;”,我在 send() 之后看不到任何响应。所以我只是希望有人能帮我检查一下有什么问题。
<html>
<head>
<title>weather app</title>
</head>
<body>
<script language="JavaScript">
function httpGet()
{
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType)
xmlHttp.overrideMimeType('text/xml');
}
else if (window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
}
xmlHttp.open( "GET", "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP?ZIP=85281", false );
alert("1 " +xmlHttp.readyState);
xmlHttpRequest.onreadystatechange = processRequest;
alert("2 " +xmlHttp.readyState);
xmlHttp.send();
alert("3 " +xmlHttp.readyState);
document.write(xmlHttp.responseText);
return xmlHttp.responseText;
}
httpGet();
</script>
</body>
</html>