1

I am created a AngularJs Post request.The request contain a long process take more than 2 minutes for perform that.But my angular request return null error after 15 seconds.request perfectly working and no error.But angular request time out with in 15 seconds

 $http.post('/api/evaluateOmrExamination',{exam_id:$scope.curExam.id})
            .success(function(data,status,headers,config){
                $scope.showProgress=false;
                ngNotify.config({
                    theme: 'pure',
                    position: 'top',
                    duration: 3000,
                    type: 'info',
                    sticky: false,
                    button: true,
                    html: false
                });

                ngNotify.set('Evaluate Examination Completed Successfully');

                $scope.errorLists=data;
            }).error(function(data,status,headers,config){
                console.log(data);
                //$scope.showProgress=false;
            });

I am also set time out in angular but no use.

 app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.timeout = 10000000;
 }]);

I need your suggestions

Shahid Neermunda
  • 1,317
  • 1
  • 14
  • 28

2 Answers2

1

Short term fix is to increase your server's timeout (this is not a client / Angular issue). You say you're using LAMP, so you must configure PHP's max_execution_time property in php.ini to a larger value. You may also need to configure Apache's timeout in httpd.conf.

Long term fix, the request could return immediately (i.e. not 2 minutes or even 15 seconds later). This doesn't mean the job is done, just that the request to perform the job is done. Then you can ping your server every X seconds to see if the job is complete, and then get the data to display to the user. It seems like more work, and it may take a little more time, but I've found that it can be easier to develop and debug this way instead of having single monolithic requests that do a lot of work. In addition to being a better user experience :)

Charlie Schliesser
  • 7,851
  • 4
  • 46
  • 76
0

There are some good recommendations here.

app.factory('timeoutHttpIntercept', function ($rootScope, $q) {
    return {
        'request': function(config) {
            config.timeout = 10000000;
            return config;
         }
    };
});

And in your config:

$httpProvider.interceptors.push('timeoutHttpIntercept');
Jack Ryan
  • 1,287
  • 12
  • 26