gpt4 book ai didi

javascript - $http.post 不是函数

转载 作者:可可西里 更新时间:2023-11-01 16:23:48 26 4
gpt4 key购买 nike

我正在尝试将表单数据提交到我创建的 API 端点。我已经在 PostMan 中测试过了,API 运行良好,我可以成功获取数据。但是在将该 API 端点连接到 angular js 中的函数时,出现以下错误。

enter image description here

这是我的代码:

 $scope.saveSession = function() {

$http.post("/session/survey", $scope.session).success(function(data, status) {
$window.location.href = '/';

console.log("Sucessfully getting data" + JSON.stringify(data));
})
}

注意:

$scope.session 是一个使用 ng-model 标签填充的对象。例如:

<input type="text" ng-model="session.title">

编辑( Controller 代码):

// This is our controller for the bio page
var session = angular.module('session', ['sessionService'])

session.controller('sessionCtrl', function($scope, $http, $window, sessionServices) {

$scope.session = {};

$scope.saveSession = function() {

$scope.session.sessionNo = 1;
$scope.session.coach = "mmmm";
$scope.session.modules = "wokr place";

//console.log(user);
$http.post("/session/survey", $scope.session).success(function(data, status) {
$window.location.href = '/';
console.log("Sucessfully getting added bio" + JSON.stringify(data));
})
};

});

最佳答案

那是因为 .success() 实际上不是一个函数。作为the documentation explains , $http.post() 返回一个 promise ,您可以将其与 .then()

链接起来
$http.post('/someUrl', data, config).then(successCallback, errorCallback);

关于javascript - $http.post 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41075792/

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