SYSK 309: How To Cancel a Web Service Request

AJAX makes asynchronous invocation of web service methods very easy. For example, the line below instantiates a web service proxy (MyService) and calls a method (MethodX):

 

var request = new MyService().MethodX(param1, param2, OnRequestComplete, OnError);

 

The question is: if you needed to cancel this request (e.g. it’s a resource intensive request and the user is navigating to another page, or a user made a request with different parameters but the previously submitted request has not been completed, etc.), how can you accomplish it?

 

As it turns out, it’s quite simple as well:

 

// Abort previously submitted request

request.get_executor().abort();

 

Special thanks to Steve Marx for the information.