gpt4 book ai didi

javascript - Post 方法抛出错误

转载 作者:行者123 更新时间:2023-12-02 16:36:35 24 4
gpt4 key购买 nike

我正在尝试基于教程 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>
...

Controller .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

关于javascript - Post 方法抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com