AngularJs-$ http.get请求,带有-1状态码的响应 [英] AngularJs - $http.get request, response with -1 status code

查看:48
本文介绍了AngularJs-$ http.get请求,带有-1状态码的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在构建使用Java在Tomcat7中部署的REST Web服务.和具有HTML/AngularJS的客户端.

I've been building a REST Web service, deployed in Tomcat7, with Java; and client with 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 ),并以纯文本形式发出问候.

This simple method in server side seems to be working when invoked from browser using right URL (http://localhost:8080/some-path/hello) and gives hello as plain text.

Tomcat日志文件中的所有内容似乎都正确.

Everthing seems right in Tomcat log files as well.

但是,有了这段代码,

$http({ 
        url: 'http://localhost:8080/some-path/hello',
        method: 'GET'

        }).then(
            function (response){
                $scope.passCheck = response.data;
            },
            function (response){
                $scope.passCheck = response.status ;
            }
    );

我正在获取-1状态代码(总是执行第二个响应函数).

I'm getting -1 status code (Always second response function executes).

有人可以帮我吗?

推荐答案

整日解决.问题是我没有与项目本身一起部署html文件.我在项目中创建了相同的html文件,并且工作正常.

Solved after working on it whole day. The problem was I was not deploying html files together with the project itself. I created the same html file in the project and it worked fine.

这篇关于AngularJs-$ http.get请求,带有-1状态码的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆