<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: cancel code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 14:28:57 GMT</pubDate>
    <description>DZone Snippets: cancel code</description>
    <item>
      <title>OnlyOneOfClass: Extension to prototype library allowing AJAX calls to supercede / abort / cancel previous calls within a given class.</title>
      <link>http://snippets.dzone.com/posts/show/1367</link>
      <description>&lt;code&gt;&lt;br /&gt;// Extension to Ajax allowing for classes of requests of which only one (the latest) is ever active at a time&lt;br /&gt;// - stops queues of now-redundant requests building up / allows you to supercede one request with another easily.&lt;br /&gt;&lt;br /&gt;// just pass in onlyLatestOfClass: 'classname' in the options of the request&lt;br /&gt;&lt;br /&gt;Ajax.currentRequests = {};&lt;br /&gt;&lt;br /&gt;Ajax.Responders.register({&lt;br /&gt;	onCreate: function(request) {&lt;br /&gt;		if (request.options.onlyLatestOfClass &amp;&amp; Ajax.currentRequests[request.options.onlyLatestOfClass]) {&lt;br /&gt;			// if a request of this class is already in progress, attempt to abort it before launching this new request&lt;br /&gt;			try { Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}&lt;br /&gt;		}&lt;br /&gt;		// keep note of this request object so we can cancel it if superceded&lt;br /&gt;		Ajax.currentRequests[request.options.onlyLatestOfClass] = request;&lt;br /&gt;	},&lt;br /&gt;	onComplete: function(request) {&lt;br /&gt;		if (request.options.onlyLatestOfClass) {&lt;br /&gt;			// remove the request from our cache once completed so it can be garbage collected&lt;br /&gt;			Ajax.currentRequests[request.options.onlyLatestOfClass] = null;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;});&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 06 Feb 2006 22:34:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1367</guid>
      <author>matth (Matthew)</author>
    </item>
  </channel>
</rss>
