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




Special thanks to Steve Marx for the information.



Comments (1)

  1. Keith says:

    The below will allow to suppress/change the onFail for a userInitiated abort

    if (request != null) { request._executor._webRequest.completed = someOtherFunction; request.get_executor().abort();          }

Skip to main content