2

i'm trying to send to a ws a post request using some parameters.

in Ajax i do:

$.post("http://myWS",{name:"xxx",surname:"yyy"},function(response){
   console.log(response);
});

this generate that payload:

{name:"xx",surname:"yyy"}

In AngularJS i do:

return $http({
    method: 'POST',
    async : true,
    cache : false,
    url: "http://myWS",
    data: {name:"xxx",surname:"yyy"},
});

And this generates that paylaod:

{"name":"xxx","surname":"yyy"}

As you can see this payload differs from ajax one.

I tried to add header to $http request:

headers: {'Content-Type': 'application/x-www-form-urlencoded'}

but results is the same.

what could be the problem?? thanks!

8
  • The angular.js request payload seems to be valid JSON, in contrast to the payload of the jQuery Ajax call. Commented Mar 4, 2014 at 10:59
  • that is not output but request payload Commented Mar 4, 2014 at 10:59
  • Thats want I meant. Sorry. Commented Mar 4, 2014 at 11:00
  • valid JSON is the ajax one not the angularjs one Commented Mar 4, 2014 at 11:01
  • jsonlint.com will tell you the exact otherwise ;-) Commented Mar 4, 2014 at 11:02

1 Answer 1

2

I solved setting headers and params in this way:

return $http({
    method: 'POST',
    async : true,
    cache : false,
    url: "http://myWS",
    data: $.param({name:"xxx",surname:"yyy"}),
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
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.