<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'weather.jsp' starting page</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.5.js"></script>
</head>
<script type="text/javascript">
$().ready(function() {
$("#text").focusout(function() {
var vv = this.value;
var myxml = '<?xml version="1.0" encoding="utf-8"?>'
+ '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'
+ '<soap12:Body><getWeatherbyCityName xmlns="http://WebXml.com.cn/">'
+ '<theCityName>'+ vv +'</theCityName>'+'</getWeatherbyCityName></soap12:Body></soap12:Envelope>';
$.ajax({
url:'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx',
dateType:'xml',
type:'post',
contentType:'application/soap+xml;charset="UTF-8"',
data:myxml,
success:function(dt){
$("#weather").empty();
$(dt).find("string").each(function() {
var $div = $("<div/>");
$div.css("color","blue");
$div.text($(this).text());
$("#weather").append($div);
$("#weather").append($("<br/>"));
});
}
},"xml");
});
});
</script>
<body>
请输入城市:<input type="text" id="text"/>
<div id="weather"></div>
</body>
</html>
webservice获取天气
最新推荐文章于 2024-09-07 13:38:28 发布