Java Web服务的Ajax Web客户端

Java Web服务的Ajax Web客户端

问题描述:

我使用netbeans和glassfich3.1开发了一个Web服务. 我想使用带有jquery ajax的Web客户端调用此服务

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;
                                                                                                                        
/**
 *
 * @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;
    }
}



使用jquery框架的客户端代码



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>



每次执行此JavaScript代码时,都会显示一条错误消息
我真的不知道问题



Every time I execute this JavaScript code it displays an error message
I am really do not know the problem

(文档).ready(功能(){ var messagews = ' ?xml version ="1.0"编码="UTF-8"?>' + ' < S:信封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>';
(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>';


( " ).click(功能 (){
("button").click(function(){


.ajax( { url:" , 类型:" , dataType:" , 数据:messowws, contentType:' text/xml; charset ="utf-8"', 成功:功能(结果){警报(" ); }, 错误:功能(){警报(" );} }); }); }); </script>
.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>



每次执行此JavaScript代码时,都会显示一条错误消息
我真的不知道问题所在



Every time I execute this JavaScript code it displays an error message
I am really do not know the problem