Terminating AJAX threads

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2007
Posts: 1
Reputation: tshivaraj is an unknown quantity at this point 
Solved Threads: 0
tshivaraj tshivaraj is offline Offline
Newbie Poster

Terminating AJAX threads

 
0
  #1
Aug 9th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Terminating AJAX threads

 
0
  #2
Aug 13th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Terminating AJAX threads

 
0
  #3
Aug 14th, 2007
Originally Posted by tshivaraj View 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
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC