AngularJs - $http.get request, response with -1 st

2019-07-27 11:32发布

问题:

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();
}

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.

Everthing seems right in Tomcat log files as well.

But, with this piece of code,

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

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

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

Could anyone help me with this?

回答1:

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.