Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery使用JSON JAX-WS web服务_Json_Web Services_Jquery_Jax Ws - Fatal编程技术网

jQuery使用JSON JAX-WS web服务

jQuery使用JSON JAX-WS web服务,json,web-services,jquery,jax-ws,Json,Web Services,Jquery,Jax Ws,我尝试利用jQuery使用JSON JAX-WS web服务,使用 我试图按照他们的指示进行操作,但无法从javascript客户端调用JAX-WSWeb服务,尽管web服务已成功构建 这是我的密码: 服务器端: @BindingType(JSONBindingID.JSON_BINDING) @WebService public class Greeting { public Book get(@WebParam(name="id") int id) {

我尝试利用jQuery使用JSON JAX-WS web服务,使用

我试图按照他们的指示进行操作,但无法从javascript客户端调用JAX-WSWeb服务,尽管web服务已成功构建

这是我的密码:

服务器端:

@BindingType(JSONBindingID.JSON_BINDING)    
@WebService 
public class Greeting
{       
    public Book get(@WebParam(name="id") int id) {
        Book b = new Book();
        b.id = id;
        return b;
    }

    public static final class Book {
        public int id = 1;
        public String title = "Java";
    }

}
客户端:

<header>
<script src="http://localhost:8080/webservice/soap/greeting?js"> </script>
    $(document).ready(function()  {
        $("#btnJson1").click(function() {
             document.getElementById("jsonprompt").innerHTML="Start JSON --- ";
             GreetingService.get(
              {id:5},
              function(r) {
                  document.getElementById("jsonprompt").innerHTML="Book Title: " + r.title;
                  }
            );
    } );
</header>

$(文档).ready(函数(){
$(“#btnJson1”)。单击(函数(){
document.getElementById(“jsonprompt”).innerHTML=“启动JSON----”;
欢迎服务(
{id:5},
功能(r){
document.getElementById(“jsonprompt”).innerHTML=“书名:”+r.Title;
}
);
} );
如有任何意见或建议,将不胜感激

如果有任何解决方案使用jQuery over JSON来使用JAX-WS服务,我们也会非常感激


提前感谢。

我找到了两种解决问题的方法

第一个是在客户端使用javascript中的XMLHttpRequest(这与jQuery并没有真正的关系),并像我在问题中提到的那样对JSON服务器进行“POST”调用

第二条如下

在服务器端,我使用库创建了一个JSON JAX-WS web服务

在客户端,只需使用jQuery库进行如下json调用

$(document).ready(function()  { 
    $("#btnJson").click(function() {
    alert("Start JSON --- ");
    $.post( "http://localhost:8080/webservice/json/scheduler",
            '{"get":{"id":5}}', 
              function(r) {
            alert("Book Title: " + r['return'].title);
            }, 
            "json" ) ; 
       }
    })
}

Firebug上的错误日志:未定义GreetingService。这看起来不正确。在您的回答中,您有一个SOAPBinding,但您正在谈论使用JSON。我只想实现一个支持jQuery JSON调用的Jax ws web服务,幸运的是,此解决方案解决了我的问题。您有什么建议吗?非常感谢D
$(document).ready(function()  { 
    $("#btnJson").click(function() {
    alert("Start JSON --- ");
    $.post( "http://localhost:8080/webservice/json/scheduler",
            '{"get":{"id":5}}', 
              function(r) {
            alert("Book Title: " + r['return'].title);
            }, 
            "json" ) ; 
       }
    })
}