GeekOnGadgets
GeekOnGadgets

Reputation: 959

$http.post data format in AngularJs

Problem Question:

I am making a post call to my API but keep on getting 500 server error. After doing some debugging API is expecting data in different format

API excepting --

user[email] -- json would be {user =>{email=>'[email protected]'}

I am sending as

return $http.post(urlBase + '/users/password',{email: email});
json is like {"user":"[email protected]"}

Recently started learning. So please guide me or provide me with any resources.

Upvotes: 0

Views: 1269

Answers (2)

Kalhan.Toress
Kalhan.Toress

Reputation: 21901

try this one,

$http({
    method: 'POST',
    url: urlBase + '/users/password',
    data: $.param({email: email})               
});

OR

 $http({
    method: "POST",
    url: urlBase + '/users/password',
    params: {email: email}                         
);

Upvotes: 0

Denis C de Azevedo
Denis C de Azevedo

Reputation: 6298

Try to send this:

{"user": {"email":"test@test"}}

This is similar to:

user.email = "test@test";

In your case:

return $http.post(urlBase + '/users/password',{user:{email: email}});

This is a good reference for this: JSON Syntax

Upvotes: 1

Related Questions