Divya MV
Divya MV

Reputation: 2053

angularjs:timeout not working in $http POST request

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

Upvotes: 3

Views: 9976

Answers (3)

Om Shankar
Om Shankar

Reputation: 283

Below syntax will works

$http.post(url, parms, {timeout: 60000}).then(function(success){}, function(error){})

Upvotes: -1

Divya MV
Divya MV

Reputation: 2053

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; 

Upvotes: 1

Jonathan Smith
Jonathan Smith

Reputation: 2599

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");
    });
 }
});

Upvotes: 3

Related Questions