1
if (xhr != null) { // xhr is AJAX call request object.
    console.log("abort");
    canceler.resolve();
}

xhr = $http({ method: 'POST', url:("/Home/GetLibrary"), timeout: canceler.promise })
    .success(){
        alert("success");
    })
    .error() {
        alert("error");
    });

Here I check the xhr object. If xhr object is not null then I abort the call. But it aborts the current call, not the previous Ajax call.
I try to call the same function again, then all subsequent AJAX call are aborted.

2 Answers 2

1

try this

 var canceller = $q.defer();
     
    $http.get("yourUrl", { data:data })
         .then(function(response){
            $scope.movie = response.data;
        });
     
    $scope.cancel = function(){
        canceller.resolve("user cancelled");  
    };

$scope.cancel();

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

1 Comment

I tried this. but $scope.cancel function is not called any cases.
0

You can do it through promises. Have a look at Aborting AJAX Requests Using $http And AngularJS, the guy explained the topic very well.

Also check the following question :

How to cancel an $http request in AngularJS?

Comments

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.