81,092
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript调用webservice</title>
<style type="text/css">
input
{
width:200px;
}
</style>
<script type="text/javascript" src="jquery.js">
<script type="text/javascript">
//参考网址:http://www.cnblogs.com/Dot-Boy/archive/2008/10/26/1257159.html
$(function(){
/*
1、WebService请求类型都为Post,WebService的Url为“[WebServiceUrl]/[WebMethod]”
2、contentType声明为Json
3、data要用Json的字符串格式传入
4、设置了dataType为json后,result就直接为返回的Json对象。
*/
//调用无参数方法
$("#btnHelloWorld").click(function(){
$.ajax({
type: "POST",
contentType:"application/json",
url:"http://localhost:8080/WebServiceShow/services/GISWebService?wsdl/showTime",
data:"{}",
dataType:'json',
success:function(result){
alert(result.d);
}
});
});
</script>
</head>
<body>
<h1>采用jQuery+ajax实现</h1>
<form action="">
<input type="button" id="btnHelloWorld" value="ShowTime" />
</form>
</body>
</html>
我的webservice地址是http://localhost:8080/WebServiceShow/services/GISWebService?wsdl,想调用的方法是showTime();package com.xiaoair.service;
public interface IGISWebService {
public String example(String message);
public String showTime();
}
实现代码:package com.xiaoair.service;
public class GISWebServiceImpl implements IGISWebService {
public String example(String message) {
return message;
}
public String showTime() {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String time = sdf.format(new java.util.Date());
return time;
}
}
哎,忙了好久,还是忙不出结果,希望各位了解这方面知识的大侠指点一下,在JavaScript里面调webservice都是调用的.net的webservice吗?调个java发布的webservice咋就这么难呢?