0

This is a function that gets executed after submitting a form which then submits data to an api, all of this is being done in angular 1.5 using the $http service

I have used postman to test this methods(GET,DELETE,POST) and others and they all work fine. In my app though POST for some reason seems note to work even though in postman i follow the same structure.

the error i get is that name is a requirement which i belie is the API ensuring information is entered.

I just cant seem to understand why this works fine in post man but not within my angular application. any help would be greatly appreciated.

 function createDocument(newMovie){


            var req = {
                method: 'POST',
                url:{{some url}},
                headers: 
                      { 
                        "Authorization": Authorization,
                        "content-type": "application/json"
                      },
                body: { 
                        "name": newMovie.name, 
                        "description": newMovie.description, 
                        "imgs":[
                           {
                             "url": newMovie.imgs
                           }
                        ]
                      }
             }  


            $http(req)
                .success(function(response){
                    console.log('success', response);
                })
                .error(function(response){
                    console.log('error', response);
                })
                ;
        }
1

1 Answer 1

1

It should be data, not body.

data: { 
                        "name": newMovie.name, 
                        "description": newMovie.description, 
                        "imgs":[
                           {
                             "url": newMovie.imgs
                           }
                        ]
                      }
Sign up to request clarification or add additional context in comments.

3 Comments

is it just something to do with angularJS or the $http service?
Yes, actually for it with the object with name data.
whatever data you pass, its name should be data.

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.