ajax请求webservice

页面导航:首页 > 软件编程 > Java编程 > ajax请求webservice

ajax请求webservice

来源: 作者: 时间:2016-01-21 09:39 【

script type=text/javascript function reqWebService(){ var name=document.getElementById(name).value; //获取XMLHttpRequest var request=GetXmlHttpObject(); ...
<script type="text/javascript">
 
function reqWebService(){
     
    var name=document.getElementById("name").value;
    //获取XMLHttpRequest
    var request=GetXmlHttpObject();
    //设置回调函数
    request.onreadystatechange=function(){
        if(request.readyState==4 && request.status==200)
        {
            var result=request.responseXML;
            alert(result);
            var returnEle=result.getElementsByTagName("return")[0];
            var value=returnEle.firstChild.data;
            alert(value);
        }
    }
     
    //打开连接
    request.open("POST","http://localhost:8090/sayhello");
    //设置请求头
    request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    request.send('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><atguigu><name>yuanhai</name><password>123456</password></atguigu></soap:Header><soap:Body><sayHello xmlns="http://server/"><arg0>'+name+'</arg0></sayHello></soap:Body></soap:Envelope>');
     
     
}
 
 
 
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
</script>
</head>
<body>
用户名:<input id="name" name ="username" value="" />
<button onclick="reqWebService()">Ajax请求webservice</button>
</body>
</>

 

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <