Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs:timeout not working in $http POST request

Tags:

angularjs

I have the following snippet in my code which set a timeout in milliseconds for the request.But its not cancelled even if the timeout is met.

var httpURL = {
            method : URLobj.method,
            url : urlString,
            data : data,
            withCredentials : true,
            headers : URLobj.headers,
            timeout:200
    };

    this.$http(httpURL).success(successFunc).error(errorFunc);

Can someone please shed some light on how this timeout parameter can be used.I am using v1.2.26.

service invocation

like image 506
Divya MV Avatar asked May 16 '26 16:05

Divya MV


2 Answers

This would be how you create a $http call with a timeout

$http({
        method: URLobj.method,
        url: urlstring,
        withCredentials : true,
        headers: URLobj.headers,
        timeout: 200
     }).success(function(data){
        // With the data succesfully returned, call our callback
        successFunc(data);
    }).error(function(){
        errorFunc("error");
    });
 }
});
like image 142
Jonathan Smith Avatar answered May 21 '26 07:05

Jonathan Smith


I had config.timeout = deferred.promise; in one of my interceptor which had overridden the value that i have set. Commenting it out worked for me.

config.timeout = deferred.promise; 
like image 32
Divya MV Avatar answered May 21 '26 07:05

Divya MV