Angularjs到restfull Web服务连接

Angularjs到restfull Web服务连接,angularjs,Angularjs,我已经创建了一个restfull web服务(例如:),我正在尝试使用angularjs连接该restfull web服务,但失败了 我的示例代码是 $http.get('http://localhost:8080/RestfulAndAngularJS_Server/rest/product/findall').success(function(response){ $window.alert('success') }).error(function(data, status, heade

我已经创建了一个restfull web服务(例如:),我正在尝试使用angularjs连接该restfull web服务,但失败了

我的示例代码是

$http.get('http://localhost:8080/RestfulAndAngularJS_Server/rest/product/findall').success(function(response){
  $window.alert('success')
}).error(function(data, status, headers, config) {
  $window.alert('failure')
});

我想立即解决这个问题,如果有人有答案或示例代码,请发邮件给我。

请检查您的REST是否可以与Google postman一起正常工作

当您在restfull web服务中返回Json格式的数据时,请在您的web服务中添加以下突出显示的内容


返回Response.status(200).entity(empList)。标题(“访问控制允许来源”,“*”).build()

看看。

你能得到一个比“失败”更具体的错误吗?你应该在控制台中公布你得到的错误,如果有的话。你在控制台日志中得到的是什么?您的服务器端方法是get。您可以展示您的服务器方法吗?在控制台中,我没有收到任何错误,但我希望成功并从restfull Web服务获取数据,我的数据类似于restfull Web服务中的数据,如{“product”:[{“id”:“p01”,“name”:“name 1”,“price”:“3000.0”},{“id”:“p02”,“name”:“name”:“name 2”,“price”:“4000.0”},{“id”:“p03”,“name”:“name 3”,“price”:“5000.0”},{“id”:“p04”,“name”:“name 4”,“price”:“6000.0”}]}请不要,按预期使用访问控制,只将您需要的域列为白名单。