Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Web Technology by (47.6k 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 (106k 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
asked Aug 30, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...