V
V
vvrider2016-01-10 23:05:59
API
vvrider, 2016-01-10 23:05:59

How to make a put request with api in angular?

How to make a put request with api in angular?
You need to make a PUT request to the API backend and pass the parameters:
{
"params" : ["apple", "potato"]
}
Tried following the example, but it doesn't work) I started to understand Angular quite recently

var myApp = angular.module("myApp", []);
    myApp.controller("HttpPutController", function ($scope, $http) {

        $scope.UpdateData = function () {
            var data = $.param({
                зфкфьі:  ["apple", "potato"] ,
               
            });

            $http.put('http://*****/getmenu?'+ data)
            .success(function (data, status, headers) {
                $scope.ServerResponse = data;
            })
            .error(function (data, status, header, config) {
                $scope.ServerResponse =  htmlDecode("Data: " + data +
                    "\n\n\n\nstatus: " + status +
                    "\n\n\n\nheaders: " + header +
                    "\n\n\n\nconfig: " + config);
            });
        };
    });

(PS **** - hid the yurlka).
Thanks a lot in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-01-10
@vvrider

var data = $.param({
                зфкфьі:  ["apple", "potato"] ,
               
            });

what is this?
mmm... why do you have data in the query string and not in the request body? How sense then PUT request to do?
As far as I remember Monga has a normal REST api.
It should be something like this:
$http.put('/some/url', {
    someKey:  ["apple", "potato"] ,
}).then(function (response) {
    // не пользуйтесь .success/.error
}, function (reason) {
    // пользуйтесь только промисами.
});

that is, no perversions and kindness. And don't use $.params. Generally. For query string, angular has a separate setting in the query config.
$http.get('/something', {
    params: {
         query: 'param'
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question