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

前端之家收集整理的这篇文章主要介绍了如何在Angularjs $http.post中传递参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在这里,我试图将“$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})

该变量将在参数过程中到达服务器

原文链接:https://www.f2er.com/angularjs/140514.html

猜你在找的Angularjs相关文章