Gunjan Patel
Gunjan Patel

Reputation: 2372

Angular $http.post request send double request.?

I am using Angular $http.post request and my response come's after approx 5-8 min so Angulars fails here because when response not comes in particular time than it send back 2nd request how can we set time for request's response come to wait ?

Upvotes: 1

Views: 1504

Answers (1)

harishr
harishr

Reputation: 18055

there is a timeout property in $http which you can use.

example with get below

app.run(function($http, $q, $timeout){

  var deferred = $q.defer();

  $http.get('/path/to/api', { timeout: deferred.promise })
    .then(function(){
      // success handler
    },function(reject){
      // error handler            
      if(reject.status === 0) {
         // $http timeout
      } else {
         // response error status from server 
      }
    });

  $timeout(function() {
    deferred.resolve(); // this aborts the request!
  }, 1000);
});

read more about it in docs

Upvotes: 1

Related Questions