Opened 11 years ago

Closed 11 years ago

#7083 closed enhancement (wontfix)

Allowing AJAX calls to supercede / abort / cancel previous calls within a given class

Reported by: guest Owned by: anonymous
Priority: high Milestone: 1.2
Component: Core Version: 1.1.1
Keywords: Cc:
Blocked By: Blocking:

Description

Please take a look a this Prototype extension.

http://snippets.dzone.com/posts/show/1367

Would it be possible to add this feature to Dojo?

Here's an example how I would use it.

dojo.xhrGet ({

Location of the HTML content we want to grab url: '/demo-0.9/xhr/content.html',

onlyLatestOfClass: 'classname',

Called when the page loaded successfully load: function (data) {

dojo.byId('html-content').innerHTML = data;

},

Called if there was an error (such as a 404 response) error: function (data) {

console.error('Error: ', data);

}

});

Change History (1)

comment:1 Changed 11 years ago by James Burke

Resolution: wontfix
Status: newclosed

Since dojo.xhrGet returns a dojo.Deferred object, you can create your own wrapper to do this. This is not a common enough use case to warrant inclusion in at least Dojo Core.

Here is how you could do it in your code (untested code, but should hopefully give the idea):

dojo.provide("mymodule.mostRecentXhr");

mymodule.mostRecentXhr = {
  _types: {},

  get: function(/*dojo.xhrGet argument object*/args, /*String*/type){
    if(this._types[type]){
      //There is one of this type in flight, kill it.
      //Objects in this._types are dojo.Deferred objects
      //with a cancel method.
      this._types[type].cancel();
    }
    return (this._types[type] = dojo.xhrGet(args));
  }
}

Note: See TracTickets for help on using tickets.