如何摆脱Uncaught SyntaxError:角度js中的意外标记a

时间:2016-01-15 12:13:07

标签: java angularjs angularjs-controller

当我尝试在代码下面运行时出现错误: SyntaxError:意外的令牌a    at Object.parse(native)    在pc(https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:14:219)    在Yb(https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js:76:201

这是我的index.html文件,当表单提交时,我通过$ http post方法将数据发布到服务器,并尝试通过$ http get方法从服务器获得响应

的index.html

<form ng-app="myApp" ng-controller="validateCtrl" name="myForm" ng-submit="employeeLogin(my)">
    <input type="email" ng-model="my.employeeEmail">
    <input type="password" ng-model="my.employeePassword">
    <button type="submit">Submit</button>
</form>

<script>
    var app = angular.module('myApp', []);
    app.controller('validateCtrl', function($http, $scope) {
        $scope.employeeLogin = function(my) {
            var formData = {
                "employeeEmail": $scope.my.employeeEmail,
                "employeePassword": $scope.my.employeePassword
            }
            $http.post("http://localhost:8080/TheSanshaWorld/sfcms/employeeLogin", formData).success(function(data) {
                $http.get('http://localhost:8080/TheSanshaWorld/sfcms/employeeLogin').success(function(data) {
                    console.log(data); //Uncaught Exception E
                    $scope.stores = data;
                });
            });
        }
    });

</script>

这是我的控制器,在这里我将员工数据发布到服务器并返回员工角色并希望存储在角色变量中。在这里我得到了服务器的响应并得到了数据,但是当这些数据传递给客户端时,我们得到了Uncaught Exception错误:

EmployeeLoginController.java

    @Controller
    @RequestMapping({"/sfcms/**"})
    public class EmployeeLoginController {
      @Autowired
      EmployeeLoginService employeeloginservice;
      @RequestMapping(value = "/employeeLogin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
      public @ResponseBody String employeeLogin(@RequestBody EmployeeDetailDto employeeDetail){
    String role= employeeloginservice.employeeLogin(employeeDetail.getEmployeeEmail() , employeeDetail.getEmployeePassword());
    return role;
    }

0 个答案:

没有答案