For my Angularjs application in services I have used Ajax call to get the data and is as follows :
var originalRequest = $.ajax({
async : false,
url : "/dash/dashboard2ajax.do",
type : "POST",
data : {
action : 'getNetSpendOverTime',
customerId : selectedAccTd,
carriersId : selectedCarriers,
fromDate : formattedFromDate,
toDate : formattedToDate
},
dataType : "json",
success : function(originalRequest) {
var res = originalRequest;
data = res.ResultSet.Response;
}
});
Then I just return (data) from my service and in my controller I am able to get data without any problem. But I realized it is a bad practice and trying to use promises. So I have replaced it as follows:
var originalRequest = $http({
url: "/dash/dashboard2ajax.do",
method: "POST",
data: {action : 'getNetSpendOverTime',
customerId : selectedAccTd,
carriersId : selectedCarriers,
fromDate : formattedFromDate,
toDate : formattedToDate}
}).success(function(data, status, headers, config) {
return (data);
}).error(function(data, status, headers, config) {
return(status);
});
But it is not working. None of the parameters are getting even passed to my action class. Is there any mistake in my syntax?
In my action class, I am accessing the parameters as
String action = request.getParameter("action");
But it is coming as null.