I develop a web service using netbeans and glassfich3.1
I want to call this service using a web client with jquery ajax
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService(serviceName = "CalculatriceWS")
public class CalculatriceWS {
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
@WebMethod(operationName = "add")
public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
return i+j;
}
}
client code with jquery framework
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var messagews='?xml version="1.0" encoding="UTF-8"?>'+
'<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">'+
'<S:Header/>'+
'<S:Body>'+
'<ns2:hello xmlns:ns2="http://webservice/">'+
'<name>Meher</name>'+
'</ns2:hello>'+
'</S:Body>'+
'</S:Envelope>';
$("button").click(function(){
$.ajax(
{
url:"http://localhost:8080/Calculatrice/CalculatriceWS",
type: "POST",
dataType: "xml",
data: messagews,
contentType: 'text/xml; charset="utf-8"',
success:function(result){ alert("Succeeeeeeee"); },
error: function(){alert("Error: Something went wrong");}
});
});
});
</script>
Every time I execute this JavaScript code it displays an error message
I am really do not know the problem