The main reason I was doing that was the angularjs documentation - the docs:

https://docs.angularjs.org/api/ng/service/$http#post

indicate that the helper methods (put, post, etc) all take an 'optional
configuration object', but I didn't notice that the optional configuration
object is the *third* parameter to put, not the second. That's all.
Mis-reading (or mixing up put and get in my skim of the docs). Mostly I
shared because it was one of those humbling moments of the day.

e


On Fri, Aug 22, 2014 at 4:05 PM, Ashesh Ambasta <[email protected]>
wrote:

> I think by doing $http.put(url, {data: {foo: 'baz bar'}}), you were
> confusing it with how $.ajax(<object>) is used?
>
> With $.ajax(…), the function is invoked with an object, the keys of which
> contain the method, data etc.
> That is different with $http(…) or $http.<method>(); since ofcourse, here
> we pass all of the same *keys *as in the object we pass to $.ajax(…), but
> as method parameters.
>
>
> On Friday, 22 August 2014 23:35:05 UTC+2, Eric Eslinger wrote:
>>
>> If you call $http() directly on an options object, and you want to send
>> data (put or post), the data you're sending needs to go into a data:
>> attribute on the options object.
>>
>> If, however, you call $http.put(url, options), the options object is sent
>> as if it were the data: attribute of the $http() options block.
>>
>> IOW, if you do $http.put(url, {data: {foo: 'baz bar'}}), your endpoint
>> will receive {data: {foo: 'baz bar'}}, but if you do $http({url: url,
>> method: 'PUT', data: {foo: 'baz bar'}}), your endpoint will receive {foo:
>> 'baz bar'}. To make things equal, you should instead do a $http.put(url,
>> {foo: 'baz bar'})
>>
>> That drove me 100% batty, I was getting occasional 400 malformed errors
>> as Joi was barfing on server-side validation. It also seems to be contrary
>> to the documentation. (I'm on angular 1.2.20)
>>
>> e
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to