This is a migrated thread and some comments may be shown as answers.

How to Cancel Running AJAX Request?

3 Answers 201 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 08 Sep 2010, 03:39 PM
Hi,

Is there a way to cancel an AJAX request in progress (after the onRequestStart stage)?

My use case is as follows: I have some search controls on a page with a RadGrid below.  When the search control values change, I trigger a second AJAX request to update the grid.  The DB search behind the grid can take a long time, so in this way, the user may still modify the search controls while the grid is updating.

Currently however, when the search controls change, the first grid update must complete before the next AJAX request actually fires, so there isn't really a speed improvement despite the controls being active during the grid update (the requests are queued and fired serially).  What I would like to do is cancel any running grid update when the controls change and fire the updated one.

Is this possible?  I know it isn't a limit of JavaScript since I've managed this with hand-coded JavaScript & the YUI JavaScript framework, but I can't seem to find a way to do it with RadControls nor with a cursory inspection of the jQuery docs.

Thanks!

Derek

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 08 Sep 2010, 03:51 PM
Hello Derek,

You can cancel an AJAX request in the OnRequestStart client-side event handler of your RadAjaxManager/RadAjaxPanel.  Calling set_cancel(true) prevents the request from continuing. Review this help topic for additional information.

Sincerely yours,

Pavlina
the Telerik team

 

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Derek
Top achievements
Rank 1
answered on 08 Sep 2010, 04:12 PM
I'm sorry, maybe I wasn't clear.  I want to cancel the request after the OnRequestStart stage.  In other words, after the request has already been made and the client is waiting on the server response.  Please assume the server might take up to 30 seconds to generate a response.

Thanks again,

Derek
0
Pavlina
Telerik team
answered on 09 Sep 2010, 02:24 PM
Hi Derek,

I am afraid that OnRequestStart event is the latest point where you can cancel the request on the client.

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Ajax
Asked by
Derek
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Derek
Top achievements
Rank 1
Share this question
or