[jQuery] Reusing a single XmlHttpRequest object

[jQuery] Reusing a single XmlHttpRequest object

Hi all
I've been using jQuery for a while but I'm just about to do my first
serious bit of Ajax with it and there's a piece of functionality I need.
I want to reuse a single XmlHttpObject to avoid content coming back out
of order, or I want to be able to cancel an existing request so that I
can manage the returning data. Either $.ajax({ url:'url.php',
connection:'onlyone' }) or $('div#content').cancelLoad() would probably
do the trick. I have hacked one together myself from the $.ajax method
but it's a bit of a kludge. Is there an easier way?
I've used an extension for Prototype that does something similar - you
pass in an optional connection name and that connection is reused each
time:
// Extension to Ajax allowing for classes of requests of which only one
(the latest) is ever active at a time
// - stops queues of now-redundant requests building up / allows you to
supercede one request with another easily.
// just pass in onlyLatestOfClass: 'classname' in the options of the
request
Ajax.currentRequests = {};
Ajax.Responders.register({
onCreate: function(request) {
if (request.options.onlyLatestOfClass &&
Ajax.currentRequests[request.options.onlyLatestOfClass]) {
try {
Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort();
} catch(e) {}
}
Ajax.currentRequests[request.options.onlyLatestOfClass] = request;
},
onComplete: function(request) {
if (request.options.onlyLatestOfClass) {
Ajax.currentRequests[request.options.onlyLatestOfClass] = null;
}
}
});
Cheers
Mike Stenhouse
donotremove.co.uk
contentwithstyle.co.uk
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/