在这里,我试图将"$ 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;
})
}])
来自servelet的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很新.
tym*_*eJV 20
你data应该是一个键/值对,尝试:
$http.post('javaServerlet', {course: $scope.getCourse})
Run Code Online (Sandbox Code Playgroud)
并且该变量将在参数下到达服务器 course
| 归档时间: |
|
| 查看次数: |
30961 次 |
| 最近记录: |