Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
    
The angular.js request payload seems to be valid JSON, in contrast to the payload of the jQuery Ajax call. –  TheHippo Mar 4 '14 at 10:59
    
that is not output but request payload –  JackTurky Mar 4 '14 at 10:59
    
Thats want I meant. Sorry. –  TheHippo Mar 4 '14 at 11:00
    
valid JSON is the ajax one not the angularjs one –  JackTurky Mar 4 '14 at 11:01
    
jsonlint.com will tell you the exact otherwise ;-) –  TheHippo Mar 4 '14 at 11:02

1 Answer 1

up vote 2 down vote accepted

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'}
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.