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:
var req_timer;
function makeRequest() {
clearTimeout(req_timer);
var req_timer = setTimeout(function() { XHR(); }, 100);
}
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.
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
Offline 1,250 posts
since Sep 2005