Reputation: 219
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) {
});
Upvotes: 1
Views: 4337
Reputation: 5666
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;
}]);
Upvotes: 2
Reputation: 168
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){})
Upvotes: 0
Reputation: 961
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
Upvotes: 0