`
cookieandsession
  • 浏览: 19453 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

webservice获取天气

 
阅读更多
<%@ 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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics