1

I have the following service in my Angular App:

myAngularApp.factory('myFactory', function($resource, HOST){
    return{
        getThings: function(userId, userToken){
            var connection = $resource(HOST + '/user/mypost/', {'Userid': userId, 'UserToken': userToken, 'Type': 'Read'}, {
                save: {
                    method: 'POST'
                }
            });
            var results = connection.save();
            results.$promise.then(function(data){
                results = data;
            });
            return results;
        }
    }
});

In one of my controllers, I call the above factory and its function using

myFactory.getThings($scope.someId, $scope.someToken);

When I look at the Network pane in developer tools, the POST request is sent with the correct query string parameters, but the URL is appended with the same parameters (a la GET request). How do I stop the parameters from being appended to my URL?

1 Answer 1

4

Try passing your parameters directly to your save() function and remove them from the URL parameters argument in your $resource constructor:

var connection = $resource(HOST + '/user/mypost/', {}, {save: {method: 'POST'}});

var params = {'Userid': userId, 'UserToken': userToken, 'Type': 'Read'};

var results = connection.save(params);
Sign up to request clarification or add additional context in comments.

1 Comment

Is this the only possible solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.