gpt4 book ai didi

angularjs - 如何在 Angularjs $http.post 中传递参数

转载 作者:行者123 更新时间:2023-12-03 06:36:08 25 4
gpt4 key购买 nike

在这里,我尝试将“$scope.getCourse = 'adobe'”的值传递到服务器,以便它返回相应的类(class)详细信息,从这里我可以使用响应数据中的 ng-repeat 填充列表。但是当我插入“$scope.getCourse”和servlet url时,下面的代码失败了。

var courseApp = angular.module('courseApp', []);courseApp.controller('courseCtrl', ['$scope', '$http', function($scope, $http){    //$scope.getCourse = 'adobe'; //need to pass this value to the server;    $http.post('javaServerlet', $scope.getCourse).success(function(data){        $scope.result = data.MainTopic;        $scope.lessons = data.CourseOutline;    })  }])

来自servlet的json格式

{     "MainTopic": "Adobe",    "RunningTime": "6h11min",    "Description": "Course Description comes here",    "CourseOutline":    [         { "Lessons" : "Lesson 1" , "Title" : "Introduction1" , "Duration" : "31m 27s"},        { "Lessons" : "Lesson 2" , "Title" : "Introduction2" , "Duration" : "56m 05s"},    ]}

请让我知道如何实现上述场景,我对 angularjs 很陌生。

最佳答案

您的数据应该是键/值对,尝试:

$http.post('javaServerlet', {course: $scope.getCourse})

该变量将在参数course下到达服务器

关于angularjs - 如何在 Angularjs $http.post 中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21910151/

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