为什么我的剩余api调用返回未定义的响应

时间:2019-01-23 19:12:58

标签: java angularjs ajax rest

我正在尝试创建一个登录页面,在该页面中,在后端检查登录凭据并返回数据... 所以我在前端使用Angular JS。

当我进行一次宁静的API调用时,它会检查登录凭据,但我没有从后端取回数据。

对我的API的Ajax调用返回未定义,因此我无法显示响应。数据

控制器: angular.module('myApp')

.controller('LoginCtrl', function ($scope, $location, LoginService) {

    $scope.loginData = {};
    $scope.errors = [];
    this.msg={};
    $scope.login = function () {
    if ($scope.loginData != null) {
        console.log('Login Controller');
        console.log($scope.loginData);
        LoginService.Login($scope.loginData).then(function (response) {
            console.log('Login Controller2');
            $scope.showHide="IsVisible";
            $scope.msg=response.data;
            $location.path('signIn');              
            $scope.statuscode = response.status;
            console.log(response.status);
            console.log(response.headers);
            console.log(response.config);
            console.log(response.statusText);
            console.log(response.xhrStatus);
            //console.log(statuscode);
            //console.log(msg.message);
           console.log(response.data);
           var result = response.resource;        
          // result.$status = response.status;
         //  console.log(result.$status);


        }, function (reason) {
           // $scope.errors.push(reason.data.toString());
        });

服务: angular.module('myApp')     .factory('LoginService',['$ http',function($ http){

    return {

        Login: function(loginData){
            console.log('Login Service');
            console.log(loginData.password);
            return $http.get('api/userlogin/checklogin', {params: {username: loginData.username, password:loginData.password}}) .then(testSuccess)
            .catch(testError);
            function testSuccess(response){
                console.log('Login Successful');
                console.log(response.data);
                return response.data;

                //console.log(response.data) this line prints data to console
             }

             function testError(error){
                return error;
             }

        },

如何从服务器获取数据并以html显示数据?

0 个答案:

没有答案