web服务功能在SOAP UI,但不是应用程序



我创建了一个简单的rest式web服务,并将其部署在Glassfish上。我已经能够使用SOAP UI的web服务,但在我的表示层(简单的html页面)做同样的事情时有问题。

这是我使用的ajax函数:

$(document).ready(function(){
$("#getAllCustomers").click(function(){
    alert("Button is functional");
    $.ajax({
       type: "get",
       url: "http://localhost:8080/restfulpractice/webresources/customer",
       success: function(data){
           var jsonData = $.parseJSON(data);
           alert("Callback function is functional");
           $.each(jsonData, function(i, item){
              this.after("<br><br>"+item+"<br><br>");
           });
       }
    });
});
});

按钮正常。所以听众没有问题。我已经三次检查了网址。我做错了什么?我是否可以在不调用任何服务方法的情况下检查是否从服务器获得响应?

编辑:好的,谢谢你的回答。在检查了浏览器中的响应后,我发现我需要添加一个"Access-Control-Allow-Origin"标头。如果我使用的方法看起来像这样,最好的方法是什么?
@GET
@Override
@Produces({"application/json"})
public List<Customer> findAll() {
    return super.findAll();
}
We can send cross domain request via HTTP Request call(like in C#,JAVA) but as 
you say you are using simple html page and try to make service call via ajax.
Earlier we couldn't make cross domain call using ajax call but now we can. 
You just need to set crossDomain property true which false by default in ajax 
call and except jsonp data instead of json. It might be affect your service return 
data format.
Here is one link which you can prefer for more detailing and example.  
http://www.pureexample.com/jquery/cross-domain-ajax.html
It seems your trying to make cross domain call.In that case you should need to make proper configuration for cross domain call(not just simple ajax call). 
For testing your services, there are to many browser plugins are available which you can use. like Rest-client for fire-fox, Post-man in Chrome etc. 

最新更新