9

Here i'm trying to pass the value of "$scope.getCourse = 'adobe'" to the server so that it returns the corresponding course details, from where i can populate list using ng-repeat from the response data. But the below code fails when i insert "$scope.getCourse" along with 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 format from servelet

{ 
    "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"},

    ]
}

Please let me know how to achieve the above senario, I'm very new to angularjs.

1
  • How does the code fail? Do you get a console error? Does the success function not run? Commented Feb 20, 2014 at 14:13

1 Answer 1

19

Your data should be a key/val pair, try:

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

And that variable will get to the server under the parameter course

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! Thanks a lot for ur quick response.
If there are multiple parameters, are they just comma-separated?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.