0

I have an AngularJS controller, which looks like this:

function MainController($scope, $http) {
    //code for HTTP Get
    $scope.SelectionChanged = function () {
        //some initialization code
        $http.post("/api/cinema", { film: $scope.film })
            .then(function (result) {
                //success
            }, function (result) {
                //failure
            });
    }
}

SelectionChanged is a function that binds to scope in order to make some select elements responsive.

I can see in fiddler that the object passed is something like:

{"film":["HO00000335"]}

but what i would expect would be:

{"film":"HO00000335"}

How can i do that?

Eidt:

Right now when i make a selection in my list i get the following in fiddler:

POST http://localhost:18669/api/cinema HTTP/1.1
Host: localhost:18669
Connection: keep-alive
Content-Length: 23
Accept: application/json, text/plain, */*
Origin: http://localhost:18669
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:18669/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

{"film":["HO00000262"]}
5
  • Firstly change your $scope.SelectionChanged = function SelectionChanged() { to $scope.SelectionChanged = function() { Commented Sep 10, 2013 at 11:54
  • What is the value of $scope.film? If you drop a console.log($scope.film) inside SelectionChanged what is the output? Commented Sep 10, 2013 at 11:57
  • It should be HO00000335 Commented Sep 10, 2013 at 11:58
  • @jyparask I know what you want it to be, but what is it actually? You probably just need to specify { film: $scope.film[0] }. Commented Sep 10, 2013 at 11:59
  • @AndréDion I don't know if my edit answers your question... Commented Sep 10, 2013 at 12:02

1 Answer 1

1

It looks like $scope.film is an array.

Try this:

function MainController($scope, $http) {
    //code for HTTP Get
    $scope.SelectionChanged = function () {
        //some initialization code
        $http.post("/api/cinema", { film: $scope.film[0] }) // note the [0]
            .then(function (result) {
                //success
            }, function (result) {
                //failure
            });
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.