-2

Following is my code

$http.post(url)
    .then(function(response) {
            // success
            log.debug(response.data);
            //console.log(message);
        },
        function(response) { // optional
            // failed

        });

the parameter is user_id. Please help in the issue

Sachin
  • 40,216
  • 7
  • 90
  • 102
Manak Bhardwaj
  • 101
  • 3
  • 13

3 Answers3

0

Is this what you mean?

var data = {
    "user_id" : 123
    }

$http.post(url,data)
              .then(function(response) {
                  // success
                  log.debug(response.data);
                  //console.log(message);
                },
                function(response) { // optional
                  // failed
                });
user2085143
  • 4,162
  • 7
  • 39
  • 68
0

You can use the following template.

P.S don't use the '$' sign, it was just to mark where you put the parameter data.

                $http({
                    url: '',
                    method: 'POST',
                    data: {user_id: $parameterValue}
                }).success(function (data) {
                  
                  Do Something With data

                })
Shizzle
  • 961
  • 3
  • 10
  • 27
0

A 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 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)

Credits to @fredrik

Community
  • 1
  • 1
daan.desmedt
  • 3,752
  • 1
  • 19
  • 33