Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I develop a web service using netbeans and glassfich3.1
I want to call this service using a web client with jquery ajax

Java
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
                                                                                                                        
/**
 *
 * @author Meher
 */

@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) {
        //TODO write your implementation code here:
        return i+j;
    }
}


client code with jquery framework
JavaScript
<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
Posted
Comments
Sandeep Mewara 23-Apr-12 13:39pm    
What error?
member60 24-Apr-12 0:11am    
use Improve question tag for tag for providing more details and for editing existing post don't repost same question again again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900