<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>
</>