JavaScript实现调用WebService

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JavaScript Call WebService </title>

<script type="text/javascript" src="js/jquery-1.10.0.js"></script>
<script type="text/javascript">

	$(document).ready(function(){
		
		$("#jsonButton").click(function(){
			
			var url = $("#jsonText").val();
			
			var str ="";
			
			str += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.soap.com/">';
				str += '<soapenv:Header/>';
				str += '<soapenv:Body>';
					str += '<ser:getText>';
						str += '<arg0>'+url+'</arg0>';
					str += '</ser:getText>';
				str += '</soapenv:Body>';
			str += '</soapenv:Envelope>';
			
	
			$.post("http://localhost:8080/gis/services/esbservice",str,function(data){
				$("#jsonDiv").html($(data).text());
			});
		});
		$("#htmlButton").click(function(){
			
			var url = $("#htmlText").val();
			
			var str ="";
			
			str += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.soap.com/">';
				str += '<soapenv:Header/>';
				str += '<soapenv:Body>';
					str += '<ser:getText>';
						str += '<arg0>'+url+' </arg0>';
					str += '</ser:getText>';
				str += '</soapenv:Body>';
			str += '</soapenv:Envelope>';
			
	
			$.post("http://localhost:8080/gis/services/esbservice",str,function(data){
				$("#htmlDiv").html($(data).text());
			});
		});
		
		$("#binaryButton").click(function(){
			
			var url = $("#binaryText").val();
			
			var str ="";
			
			str += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.soap.com/">';
				str += '<soapenv:Header/>';
				str += '<soapenv:Body>';
					str += '<ser:getBinary>';
						str += '<arg0>'+url+' </arg0>';
					str += '</ser:getBinary>';
				str += '</soapenv:Body>';
			str += '</soapenv:Envelope>';
			
	
			$.post("http://localhost:8080/gis/services/esbservice",str,function(data){
				$("img").attr("src","data:image/gif;base64,"+$(data).text());
			});
		});
		
	});

</script>
</head>
<body>

	<h3>页面通过ESB平台调用REST服务: 返回JSON文本数据</h3>
	<hr/>

	URL:<input id="jsonText" type="text" value="http://server.arcgisonline.com/arcgis/rest/services?f=json"/> 
	<input id="jsonButton" value="GET_JSON" type="button"/><br/><br/>
	
	<div id="jsonDiv">
	
	</div>
	
	<br/><br/>
	<h3>页面通过ESB平台调用REST服务: 返回HTML/XML文本数据</h3>
	<hr/>

	URL:<input id="htmlText" type="text" value="http://server.arcgisonline.com/arcgis/rest/services"/> 
	<input id="htmlButton" value="GET_HTML" type="button"/><br/><br/>
	
	<div id="htmlDiv">
	
	</div>
	
	<br/><br/>
	<h3>页面通过ESB平台调用REST服务: 返回图片二进制数据</h3>
	<hr/>

	URL:<input id="binaryText" type="text" value="http://sampleserver1c.arcgisonline.com/arcgisoutput/_ags_map5e57267ff6fb4227a8f8685915856213.png"/> 
	<input id="binaryButton" value="GET_BINARY" type="button"/><br/><br/>
	
	<div id="binaryDiv">
		<img alt="" src=""/>
	</div>
	
	

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值