I have an angular controller with an http.post request but I'm not getting response, the service works fine because a test it using postman.
I need to display the data from the WS in an HTLM table(I know how to do this part) when the page is loaded, I'm sendinng the body for the request in a variable name "data", the header configuration un a variable name "config" and the the http.post call to the URL of my WS.
I'm new to angular so I don't know if I'm missing something, also I want to print the response in the console to test if it's returnig what I'm expecting.
I took this code from an example I found on the web and I modify it, in the example there's a button where the call to SendData() function but I don't need a button, the call has to be made as the page is loaded.
This is the controller code
.controller("HttpGetTestController", function ($scope, $http) {
$scope.SendData = function () {
var data = {
"userId":"mdrodri",
"token":"840430482834947828876768058086529370654",
"domain":"MX",
"filters":{
"timeFrameType":"Week (FiscalYear)",
"custMembSelectionType":"TOTAL",
"locationSelectionType":"Country",
"merchandiseSelectionType":"SBU",
"startYear":"2015",
"endYear":"2015",
"startUnit":"1",
"endUnit":"1",
"comparator":false,
"locationSelections":["CA"],
"merchandiseSelections":["SBU38"],
"custMembSelections":["TOTAL"],
"metricSelections":["Product Sales (Category Rank)"],
"rankOrder":"10"
},
"additionalFilters":[],
"cache":false
};
var config = {
headers : {
'Content-Type': 'application/json;'
}
}
$http.post('http://whateverurl/', data, config)
.success(function (data, status, headers, config) {
$scope.PostDataResponse = data;
console.log("Success");
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
console.log("Data: " + data);
console.log("Status: " + status);
console.log("Headers: " + header);
console.log("Config: " + config);
});
};
})
In my HTML this is how I'm calling that controller
<div class="panel panel-default" ng-controller="HttpGetTestController">
Thank's for the time and help.
http://whateverurl/supportCORS? If it doesn't you will not be able to call it from a different domain due to the same origin policy restriction that is built into browsers. Which explains why your request works when made from Postman but not using AJAX in a browser. Just look at the console of your browser and you will see the warning saying that the request has been blocked.