1

I'm new to Angular so I'm probably making a basic mistake. I'm having trouble with the $http service. I'm declaring my method as a POST but the parameters are appended to the URL as if I'm using a GET. My code is below, any ideas?

$http({
    method: 'POST',
    url: URL,
    params: {
        Source: 'Blog',
        Header: entry.Header,
        Body: entry.Body,
        ID: entry.ID,
        IsLive: entry.IsLive
    }
}).success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {         
});
1
  • 4
    use "data" instead of "params" Commented Mar 31, 2014 at 8:51

3 Answers 3

2

Probably You are not defined 'entry'. Add it in the model ($scope.entry object) and look at example:

myControllers.factory('sqlFactory', ['$http', function($scope, $http){
var f = {};

f.get = function($scope, $http){
    var file = 'php/datasets.php';
    $http({
        method:'POST',
        url: file,
        params: {
            Source: 'Blog',
            Header: $scope.entry.Header,
            Body: $scope.entry.Body,
            ID: $scope.entry.ID,
            IsLive: $scope.entry.IsLive
        }
    })
    .success(function(data, status, headers, config) {
            //return record
            $scope._rows = data;
        }
    })
    .error(function(data, status, headers, config) {
        //return error message
        $scope._error = data;
    });
};

return f;
}]);
Sign up to request clarification or add additional context in comments.

Comments

0

You can write the $http.post method in another way like this.

$http.post(URL{Source:'Blog',Header:entry.Header,Body:entry.Body,ID:entry.ID,IsLiv:entry.IsLive})
.success(function (data, status, headers) {
    console.log(data)
}).error(function (data, status, headers) {         
});

if you don't have to set something particular in the post method, you can write it in that way. I even suggest you to log the data Response parameters. I don't know how many experience you have with the http methods around the web, so in the end i suggest you to open the web-developer console of your browser(i prefer to use the mozilla one) and see in the network panel the parameters you send with this method. I hope this could be a full explanation

Comments

0

Why are you using the "params" object? This is what is adding to your url. I am assuming that you are POSTing the params object to your server. Maybe this is what you should be doing?

var params = {
    Source: 'Blog',
    Header: entry.Header,
    Body: entry.Body,
    ID: entry.ID,
    IsLive: entry.IsLive
}
http.post(URL, params)
.success(function(data, status, headers,config){})
.error(function(data, status, headers,config){})

Comments

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.