当我执行saveUser()方法时,它显示错误,但用户可以保存到数据库中。怎么了?
错误信息:
angular1.5.3.min.js:116 SyntaxError:位于0的JSON中的意外标记g at Object.parse(native) at uc(localhost:8080 / js / angular1.5.3.min.js:17:6) at ac(//localhost:8080/js/angular1.5.3.min.js:90:253) 在//localhost:8080/js/angular1.5.3.min.js:91:164 在q(//localhost:8080/js/angular1.5.3.min.js:7:355) at ed(localhost:8080 / js / angular1.5.3.min.js:91:146) at c(/localhost:8080/js/angular1.5.3.min.js:92:403) at localhost:8080 / js / angular1.5.3.min.js:128:305 at m。$ eval(//localhost:8080/js/angular1.5.3.min.js:142:467) at m。$ digest(//localhost:8080/js/angular1.5.3.min.js:140:47)(anonymous function)@ angular1.5.3.min.js:116(匿名函数)@ angular1.5.3.min .js:89(匿名函数)@ angular1.5.3.min.js:128 $ eval @ angular1.5.3.min.js:142 $ digest @ angular1.5.3.min.js:140 $ apply @ angular1.5.3.min .js:143g @ angular1.5.3.min.js:95x @
angular1.5.3.min.js:100v.onload @ angular1.5.3.min.js:101
js file:
var app = angular.module('MyApp', ['ngResource']);
app.factory('baseRequest', ["$resource", function ($resource) {
return $resource("/apis/:id/users.req", {id: '@id'}, {
query: {method: 'get', isArray: false}
});
}]);
app.controller("MyCtrl", ["$scope", "baseRequest", function ($scope, baseRequest) {
/**
* all
*
**/
$scope.fetchAllUsers = function () {
$scope.users = baseRequest.query();
};
/**
* first show
*
**/
$scope.fetchAllUsers();
/**
* delete
*
**/
$scope.deleteUser = function (id, name) {
if (confirm("delete[" + name + "]?")) {
baseRequest.delete({id: id});
$scope.fetchAllUsers();
}
};
/**
* save
*
**/
$scope.saveUser = function (u) {
baseRequest.save(u);
$scope.fetchAllUsers();
};
}]);
这是jsp文件:
<div style="float: left;margin-left: 20px;width: 350px;">
<span>UserName:</span><input type="text" ng-model="user.name" required><br>
<span>Password:</span><input type="password" ng-model="user.password" required><br>
<span>Email:</span><input type="email" ng-model="user.email" required><br>
<input type="button" ng-click="saveUser(user)" value="save_data"><br>
<span>user'content:{{user}}</span>
</div>
</body>
答案 0 :(得分:0)
Angularjs:位于0的JSON中出现意外的标记u 由于我们只定义$ state,$ localStorage,$ routeProvider但我们没有在下面的程序中使用这些东西,所以这些是抛出错误消息的原因