我使用Eclipse和Axis2在JAVA中编写了一个简单的Web服务。我试图使用jQuery调用webservice:
<html>
<head>
<title>Calling WebService</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function callws() {
//code
var userName ='TempUser';
var password='1234';
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<Login xmlns="http://core.tst.com/"> \
<UserName>' + userName + '</UserName> \
<Password>' + password + '</Password> \
</Login> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
type: "POST",
url: "http://99.32.184.180:8080/TestLoginWS/services/BasicServices.BasicServicesHttpSoap11Endpoint?op=Login",
data: soapMessage,
contentType: "application/xml; charset=\"utf-8\"",
dataType: "json",
processData:false,
success: function(msg){
alert('Success');
},
error: function(e){
alert('Error: ' + JSON.stringify(e));
$('#p1').html(JSON.stringify(e)); }
});
}
</script>
</head>
<body>
<form>
<div>
<input type="button" value="Go" onclick="callws()" />
</div>
<br><br><br>
<p id="p1">
</p>
</form>
</body>
</html>
我得到的错误是: { “readyState的”:0 “responseText的”: “”, “状态”:0 “状态文本”: “错误”} 我在Tomcat 7下托管同一服务器上的webservice和页面。
我看到很多例子和帮助,无法解决这个问题。 任何帮助将不胜感激,thx