Welcome to MSDN Blogs Sign in | Join | Help

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.

 

 

Published Monday, March 19, 2007 6:31 AM by irenak

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SYSK 309: How To Cancel a Web Service Request

Wednesday, September 17, 2008 2:16 PM by Keith

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();          }

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker