六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 68|回复: 0

Ajax调用webservice

[复制链接]

升级  0.67%

13

主题

13

主题

13

主题

秀才

Rank: 2

积分
51
 楼主| 发表于 2013-1-29 11:53:01 | 显示全部楼层 |阅读模式
发布一下方法为webservice

public class SayHello {public String hello(String msg){return "say:"+msg;}}

调用发布的webservice,弹出结果:say:hello world
<script>var xhr;var xmlDoc;function get_mytatus(){     if (window.XMLHttpRequest) {             xhr = new XMLHttpRequest();          } else {             //  xhr = new ActiveXObject("Msxml2.XMLHTTP");             xhr = new ActiveXObject("Microsoft.XMLHTTP");          }   xhr.onreadystatechange=get_result; xhr.open("POST", "http://localhost:8080/test/services/SayHello/hello",true);xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xhr.send('msg=hello world');}function  get_result() { if   (xhr.readyState == 4) {   if(xhr.status == 200)   {   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");   xmlDoc.async="false";                    //加载返回的xml报文  xmlDoc.loadXML(xhr.responseText);                    //解析返回的报文内容  var msg=xmlDoc.getElementsByTagName("ns:return")[0].childNodes[0].nodeValue;   alert(msg);  }} } setInterval("get_mytatus()","3000");</script>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表