ASP.Net Ajax features are very good, even great if you consider the useful integration with other ASP.Net constructs. PageMethods are one of the easiest ways to implement an AJAX call without too much trouble or the need to implement a complete web service page if you’re only going to use this particular Ajax call from within this page.
But unlike web service references, aborting a PageMethods request isn’t straightforward at all. The problem is, unlike web service JS wrappers, when you call PageMethods.YourMethod(…) it doesn’t return anything (its return type is basically a void). This is surprisingly stupid in my opinion, but maybe there are reasons I’m simply not aware of.
So, in order to be able to abort a PageMethods request you need 2 things. The first, is a reference to the request being executed which can be retrieved and used like this:
var request = PageMethods._staticInstance.YourMethod(params, onSuccess, onFail);
This time the request variable will be correctly retrieved. But to properly abort the request you still need to know 1 more thing:
var executor = request.get_executor(); if(executor.get_started()) executor.abort();
That’s it, you need the executor object to access the current running request, and get_started() is just a check to make sure that: a) it has started the request already; b) it’s not done yet;
Not as simple as it should be, but not a huge work load either. Hope it helps.