1

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 ?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I have to mention above for POST request. Can i it works for POST request also ?
yes post request also do accept the config parameter.. the sequence of parameters you can check on angular-site

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.