2014-02-20 106 views
9

这里我试图将“$ 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"}, 

    ] 
} 

请让我知道如何实现上述塞纳里奥,我很新的angularjs。

+0

下怎样的代码会失败?你有控制台错误吗?成功功能不运行吗? – JeffryHouser

回答

19

data应该是一个键/值对,请尝试:

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

,并且这个变量将获得到服务器的参数course

+0

完美!非常感谢您的快速回复。 – Abilash

+0

如果有多个参数,它们只是用逗号分隔吗? – aconkey

+0

非常感谢你Abhilash,tymeJV – Ajith

相关问题