xiangsheng 发表于 2013-1-29 11:53:01

Ajax调用webservice

发布一下方法为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');}functionget_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").childNodes.nodeValue;   alert(msg);}} } setInterval("get_mytatus()","3000");</script>
页: [1]
查看完整版本: Ajax调用webservice