注意,使用ajax调用webservice时,尽量使用ie浏览器,如果使用chrome或者是firefox浏览器,会出现以下异常:
2013-8-25 17:02:30 com.sun.xml.internal.ws.transport.http.server.WSHttpHandler handleExchange
警告: Cannot handle HTTP method: OPTIONS
HTML页面代码:
<html>
<head>
<title>通过ajax调用webservice服务</title>
<script type="text/javascript">
var xhr;
function send(){
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}else if(window.ActiveXObject){
var activexName=["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for(var i=0;i<activexName.length;i++){
try{
xhr=new ActiveXObject(activexName[i]);
break;
}catch(e){
}
}
}
//服务的地址
var wsUrl="http://127.0.0.1:6789/hello";
//请求体
var soap='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://jdf.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body><q0:sayHello><arg0>aa</arg0> </q0:sayHello></soapenv:Body></soapenv:Envelope>';
//打开连接
xhr.open('POST',wsUrl,true);
//重新设置请求头
xhr.setRequestHeader("Content-Type","text/xml;charset=UTF-8");
//设置回调函数
xhr.onreadystatechange=_back;
//发送请求
xhr.send(soap);
}
function _back(){
if(xhr.readyState==4){
if(xhr.status==200){
alert("OK");
}
}
}
</script>
</head>
<body>
<input type="button" value="确定" </body>
</html>
转载于:https://blog.51cto.com/jiangdf/1282391