Currently, I am in the process of developing a single page application and utilizing Angularjs v1.2.28 for this project. In order to retrieve data from the backend, I have implemented an HTTP GET request using the following code snippet.
return {
getCategories : function(sessionid,terminalid,tableno,section){
var req = {
method: 'GET',
url: Config.url+ "/menucategories",
params : {
'sessionid' : sessionid,
'terminalid' : terminalid,
'tableno' : tableno,
'section' : section
}
};
return $http.get(req);
},
The controller relies on the promise object returned by the service, as demonstrated below.
var categoryPromise = categoryService.getCategories(sessionid,terminalid,tableno,section);
categoryPromise.then(function(payload){
var categories = payload.data;
if(categories.status.code == "1"){
if(Object.prototype.toString.call(categories) === '[object Array]') {
$scope.categories = categories;
categoryService.setCategories(categories);
$scope.pax = tableService.getPax();
$scope.tablechair = tableService.getChoseTableChair();
}
}
else{
$location.url("/login");
$scope.errorMsg = categories.status.desc;
}
},function(errorPayload){
$location.url("/login");
$scope.errorMsg = "Server error while processing the request.Please contact system administrator";
});
Despite my efforts, I have encountered an issue where the errorCallback is consistently triggered due to the URL being altered to the browser application URL with additional characters appended. The intended URL provided is as follows:
http://localhost:8080/CafexRestful/menucategories
Nevertheless, it transforms into the browser application URL displayed below:
http://localhost:8080/CafexMobile/[object%20Object]
My attempts at debugging through Chrome and Firebug have been unsuccessful thus far. It seems to be an underlying issue that requires further investigation. Strangely enough, the same code functions seamlessly with another controller and service when fetching different data. Any insights or additional information would be greatly appreciated. Thank you.