AngularJS Passing Data To $http.get Request


Answer :

An HTTP GET request can't contain data to be posted to the server. However, you can add a query string to the request.

angular.http provides an option for it called params.

$http({     url: user.details_path,      method: "GET",     params: {user_id: user.id}  }); 

See: http://docs.angularjs.org/api/ng.http#get and https://docs.angularjs.org/api/ng/service/http#usage (shows the params param)


You can pass params directly to $http.get() The following works fine

$http.get(user.details_path, {     params: { user_id: user.id } }); 

Starting from AngularJS v1.4.8, you can use get(url, config) as follows:

var data = {  user_id:user.id };  var config = {  params: data,  headers : {'Accept' : 'application/json'} };  $http.get(user.details_path, config).then(function(response) {    // process response here..  }, function(response) { }); 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?