我一直在使用 Java 构建一个 REST Web 服务,部署在 Tomcat7 中;和 HTML/AngularJS 客户端。
@GET
@Path("/hello")
@Produces("plain/text")
public Response hello(){
String hello="hello";
return Response.status(Status.OK).entity(hello).build();
}
当使用正确的 URL ( http://localhost:8080/some-path/hello ) 从浏览器调用时,服务器端的这个简单方法似乎可以正常工作,并以纯文本形式给出 hello。
Tomcat 日志文件中的一切似乎都正确。
但是,有了这段代码,
$http({
url: 'http://localhost:8080/some-path/hello',
method: 'GET'
}).then(
function (response){
$scope.passCheck = response.data;
},
function (response){
$scope.passCheck = response.status ;
}
);
我收到 -1 状态代码(始终执行第二个响应函数)。
谁能帮我解决这个问题吗?
最佳答案
经过一整天的努力解决了。 问题是我没有将 html 文件与项目本身一起部署。我在项目中创建了相同的 html 文件并且运行良好。
关于java - AngularJs - $http.get 请求,响应为 -1 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38377135/