3
.service('searchService', function ($http, $state) {
    getSearchResult: function (query) {
            return $http.get('/api/search/' + query + '/simple_search.json');
          }
});

What I need to do is destroy all the pending search request so that when a new keyword is entered only 1 request stays in process. Right now when my server is getting slow multiple http request stays in pending state so I just want to cancel the previous request each time a new request is initiated.

*This is required for handling multiple requests.

Aayush
  • 223
  • 1
  • 3
  • 13
  • You can't. Ajax is asynchounous you cannot cancel a HTTP request once it has been sent. – Liam Dec 14 '16 at 11:48
  • Possible duplicate of [How to cancel an $http request in AngularJS?](http://stackoverflow.com/questions/13928057/how-to-cancel-an-http-request-in-angularjs) – Liam Dec 14 '16 at 11:50
  • Note the above will cancel the waiting call in JavaScript, it does not "kill" the HTTP request or pevent the server from processing/responding. It merely stops listening to the response – Liam Dec 14 '16 at 11:51
  • @Liam I am not able to implement the canceler with my use case. I only want to stop the listener for previous req while initiating a new one. – Aayush Dec 14 '16 at 11:56
  • See also this answer http://stackoverflow.com/a/41125771/3731501 – Estus Flask Dec 14 '16 at 11:56

0 Answers0