+2 votes
1 view
in Web Technology by (47.8k points)

I have a function which does an HTTP POST request. The code is specified below. This works fine.

$http({

url: user.update_path,

method: "POST",

data: {user_id: user.id, draft: true}

});

I have another function for http GET and I want to send data to that request. But I don't have that option in get.

$http({

url: user.details_path,

method: "GET",

data: {user_id: user.id}

});

The syntax for http.get is

get(url, config)

1 Answer

+2 votes
by (107k points)

For passing data to $http.get request in AngularJS, an HTTP GET request can't contain data to be posted to the server. However, you can add a query string to the request. So angular.http provides you with an option for it called params

See the code below:-

$http({

url: user.details_path,

method: "GET",

params: {user_id: user.id}

});

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 30, 2019 in Web Technology by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...