[Solved] – AngularJS – Explain about passing data to $http.get request?

Explain about passing data to $http.get request?

Asked on October 19, 2018 in AngularJs.
Add Comment


  • 3 Answer(s)

    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}
    });
    
    Answered on October 19, 2018.
    Add Comment

    You can pass params directly to $http.get()

    Lets see an example:

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

     

    Answered on October 19, 2018.
    Add Comment

    You can use get(url, config) as follows:

    Let see an example:

    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) {
    });
    
    Answered on October 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.