I am facing an issue in Ionic . I am trying to abort my $http post and get request after 20 seconds forcefully and want to execute the http call error block which says "server issue found" .Is there is any way to abort http call and execute its error block forcefully after some seconds in ionic or cordova .Thanks in AdvanceIs there is any kind of parameter passed in a call to abort it after that much of seconds
Here is the correct syntax for timeout.
$http({
method: POST,
url: 'path/to/service',
timeout: 5000
}).success(function(data){
// With the data succesfully returned, call our callback
successFunc(data);
}).error(function(){
errorFunc("error");
});
}
});
Or modify the default timeout of http provider similar to following.
angular.module('MyApp', [])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.timeout = 5000;
}]);
Goodluck.
You can use timeout option in http request. If it reach the timeout limit, automatically it will execute the error block
$http.get('path/to/service', {timeout: 5000});