AngularJS passing data to $http.get request

前端 未结 7 818
无人及你
无人及你 2020-11-22 13:01

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

 $http({
   url: user.update_path, 
   method: \"POST\",
   d         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 13:18

    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)

提交回复
热议问题