Post 方法抛出错误
Post method throws an error
我正在尝试基于教程 https://docs.angularjs.org/tutorial/step_00 中的应用程序做一个测试应用程序。它工作正常,但我有 post 方法。
index.html
...
<div class="control_panel" ng-controller="phonecatControllers">
<button class="btn btn-default" ng-click="chiliSpicy()">Chili!</button>
<button class="btn btn-default" ng-click="sendData()">send!</button>
</div>
...
controllers.js
'use strict';
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http', '$log',
function ($scope, $http, $log) {
$http.get('http://localhost:8080/webapp/rest/myresource/posts').
success(function (data) {
$scope.posts = data;
});
$scope.data = "hello world";
$scope.chiliSpicy = function () {
$log.info('chili function');
};
$scope.sendData = function () {
$http.post('http://localhost:8080/webapp/rest/myresource/', {'data' : $scope.data} )
.succes(function (data, status, headers, config) { // !!! here is line 39
$log.info('sent');
})
.error(function (data, status, headers, config) {
$log.error('not sent')
});
};
}]);
Get 方法工作正常(显示 html 代码不包含其用法),chiliSpicy 函数也工作。但是 sendData 函数抛出错误(成功函数在哪里)
TypeError: undefined is not a function
at l.$scope.sendData (http://localhost:8080/webapp/controllers.js:39:18)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424
at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:798:21
at l.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:84)
at l.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:310)
at l.scopePrototype.$apply (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:1478:22)
at HTMLButtonElement.<anonymous> (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:797:25)
at HTMLButtonElement.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:32:363)
实际上是服务端收到数据,但是success函数没有通过。任何想法?谢谢。
拼写错误success
,写成succes
。
有错字。应该是 success 而不是 'succes'
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http', '$log',
function ($scope, $http, $log) {
$http.get('http://localhost:8080/webapp/rest/myresource/posts').
success(function (data) {
$scope.posts = data;
});
$scope.data = "hello world";
$scope.chiliSpicy = function () {
$log.info('chili function');
};
$scope.sendData = function () {
$http.post('http://localhost:8080/webapp/rest/myresource/', {'data' : $scope.data} )
.success(function (data, status, headers, config) { // !!! here is line 39
$log.info('sent');
})
.error(function (data, status, headers, config) {
$log.error('not sent')
});
};
}]);
我正在尝试基于教程 https://docs.angularjs.org/tutorial/step_00 中的应用程序做一个测试应用程序。它工作正常,但我有 post 方法。
index.html
...
<div class="control_panel" ng-controller="phonecatControllers">
<button class="btn btn-default" ng-click="chiliSpicy()">Chili!</button>
<button class="btn btn-default" ng-click="sendData()">send!</button>
</div>
...
controllers.js
'use strict';
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http', '$log',
function ($scope, $http, $log) {
$http.get('http://localhost:8080/webapp/rest/myresource/posts').
success(function (data) {
$scope.posts = data;
});
$scope.data = "hello world";
$scope.chiliSpicy = function () {
$log.info('chili function');
};
$scope.sendData = function () {
$http.post('http://localhost:8080/webapp/rest/myresource/', {'data' : $scope.data} )
.succes(function (data, status, headers, config) { // !!! here is line 39
$log.info('sent');
})
.error(function (data, status, headers, config) {
$log.error('not sent')
});
};
}]);
Get 方法工作正常(显示 html 代码不包含其用法),chiliSpicy 函数也工作。但是 sendData 函数抛出错误(成功函数在哪里)
TypeError: undefined is not a function
at l.$scope.sendData (http://localhost:8080/webapp/controllers.js:39:18)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424
at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:798:21
at l.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:84)
at l.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:310)
at l.scopePrototype.$apply (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:1478:22)
at HTMLButtonElement.<anonymous> (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:797:25)
at HTMLButtonElement.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:32:363)
实际上是服务端收到数据,但是success函数没有通过。任何想法?谢谢。
拼写错误success
,写成succes
。
有错字。应该是 success 而不是 'succes'
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http', '$log',
function ($scope, $http, $log) {
$http.get('http://localhost:8080/webapp/rest/myresource/posts').
success(function (data) {
$scope.posts = data;
});
$scope.data = "hello world";
$scope.chiliSpicy = function () {
$log.info('chili function');
};
$scope.sendData = function () {
$http.post('http://localhost:8080/webapp/rest/myresource/', {'data' : $scope.data} )
.success(function (data, status, headers, config) { // !!! here is line 39
$log.info('sent');
})
.error(function (data, status, headers, config) {
$log.error('not sent')
});
};
}]);