How to Cancel Running AJAX Request?

4 posts, 0 answers
  1. Derek
    Derek avatar
    2 posts
    Member since:
    Jul 2010

    Posted 08 Sep 2010 Link to this post

    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
  2. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 08 Sep 2010 Link to this post

    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
  3. Derek
    Derek avatar
    2 posts
    Member since:
    Jul 2010

    Posted 08 Sep 2010 Link to this post

    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
  4. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 09 Sep 2010 Link to this post

    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
Back to Top