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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.