如何在Angularjs $http.post中传递参数
发布时间:2020-12-17 09:28:35 所属栏目:安全 来源:网络整理
导读:在这里,我试图将“$scope.getCourse =’adobe’”的值传递给服务器,以便返回相应的课程详细信息,从中可以从响应数据中使用ng-repeat填充列表.但是当我插入“$scope.getCourse”以及servelet url时,以下代码失败. var courseApp = angular.module('courseApp'
在这里,我试图将“$scope.getCourse =’adobe’”的值传递给服务器,以便返回相应的课程详细信息,从中可以从响应数据中使用ng-repeat填充列表.但是当我插入“$scope.getCourse”以及servelet 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; }) }]) 来自服装的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"},] } 请让我知道如何实现上述情景,我对于角度很新.
您的数据应该是一个键/对,尝试:
$http.post('javaServerlet',{course: $scope.getCourse}) 该变量将在参数过程中到达服务器 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |