943,617 Members | Top Members by Rank

Ad:
Aug 9th, 2007
0

Terminating AJAX threads

Expand Post »
Hi All,

Is there a way to terminate an AJAX thread. I have an application where if a user selects multiple options in a rapid succession it causes a deadlock situation.

I would like to terminate the previous thread, if a new one is spawned. I am using prototype.

Thanks,

Shivaraj
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tshivaraj is offline Offline
1 posts
since Aug 2007
Aug 13th, 2007
0

Re: Terminating AJAX threads

I don't think there is a way to terminate the call - apart from closing the document. Prototypes are similar to objects - if you are familiar with OOP? If you have a prototype 'instance' then you can avoid deadlock situations, consider what is deadlocking and establish if it needs to be a shared resource.

If this fails, then lock down your page until the initial query has executed - I notice several sites doing this, they paint the page a darker shade... I think its a pretty crapy solution, but I guess sometimes it must be difficult to avoid.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Aug 14th, 2007
0

Re: Terminating AJAX threads

Click to Expand / Collapse  Quote originally posted by tshivaraj ...
Hi All,

Is there a way to terminate an AJAX thread. I have an application where if a user selects multiple options in a rapid succession it causes a deadlock situation.

I would like to terminate the previous thread, if a new one is spawned. I am using prototype.

Thanks,

Shivaraj
You can terminate an XMLHTTPRequest call with the abort() method (If thats what you're using for AJAX).

If you use the same XMLHTTPRequest instance, calling open() a second time will terminate the first request.

I'm sure the Prototype JavaScript Library has a corresponding method for abort().

A more efficient design would be to only call an XMLHTTPRequest if the option selected stays for over a few milliseconds.

eg:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var req_timer;
  2. function makeRequest() {
  3. clearTimeout(req_timer);
  4. var req_timer = setTimeout(function() { XHR(); }, 100);
  5. }

Then you can implement abort() also.

clearing the timeout is much more efficient that aborting the HTTP Request. Especially if you don't make sure an abort from the HTTP Client will actually terminate the Script running on the server. Some scripts will keep executing and the server sends the HTTP Response even though the browser discards it.
Last edited by digital-ether; Aug 14th, 2007 at 7:52 am.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: random slideshow with random timer...
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Problem in JS when i upgraded my Jar Files for MyFaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC