I have a JSP page which calls the Angularjs controller in js file. The Angularjs Controller calls the $http service to make a POST request to backend java based API (saveRecordToDB). Below is the code snippet. After receiving the response, the frontend displays the Successful message on the frontend.
When I execute this code for data which takes less time to complete the API (saveRecordToDB), around 1-2 minutes, then the Successful message is displayed on page.
But when I execute this code for data which take long time to complete the API (saveRecordToDB), around 40-50 mins, then the page status is not changed to Successful. I can see that all the steps in API (saveRecordToDB) are completed for both the request. It seems that for long duration request, $http doesn't catch the response from API.
JSP Page:
<div class="row" ng-if="!downloadFile">
<div class="col-sm-1" ng-if="brokerUploadCount > 0"><button ng-click="approve()" class="pull-right btn btn-success">Approval</button></div>
<div class="col-sm-1"><button ng-click="reject()" class="pull-left btn btn-danger">Reject</button></div>
</div>
<br>
<div class="row" ng-if="downloadFile">
<div class="col-sm-4">
<div class="col-sm-2"><b>SUCCESSFUL</b></div>
</div>
<script type="text/javascript" src="js/controller/Upload.js"></script>
Upload.js file:
pos.controller('excelCtrl', ['$scope', '$http', 'appService', 'FileUploader', function($scope, $http, appService, FileUploader) {
$scope.approve = function(){
var uploadUrl = "api/saveRecordToDB" ;
var dataSet = {
"period":$("#period").val(),
};
$http({
method: 'POST',
url: uploadUrl,
cache: false,
//timeout: 60 * 60 * 1000,
params: dataSet
}).success(function(data){
appService.showStatus("success");
$scope.downloadFile = true;
$scope.fileName = "";
});
}
}]);
I tried to change the timeout for $http request. But not sure if its correct. Also tried for async call.
Please can someone suggest how I can make the $http service to wait for long duration till the backend API execution completes.