PDA

View Full Version : 1.1.0 - Cancel AjaxProxy store load



damon1977
2 May 2011, 12:42 PM
I looked into how to cancel an AjaxProxy request. I couldn't find anything in the touch forums on this, and all threads in the Ext forums do not apply, so I thought I would post my findings. Tracing through the code I determined there is no way to get the Ajax transaction id or request object from when a store is loaded (without making changes to the library code itself) because the request object is never assigned to anything and looses scope.

There are a few options...


Ext.Ajax.autoAbort = true;This will make it impossible to execute more than one ajax call at a time.

Or you can do something like:


if (store.loading) Ext.Ajax.abort();This assumes no other ajax calls could be in progress other than the store load call.

Beyond that you would need to modify the AjaxProxy doRequest function to make the request object accessible. I decided not to do this, but if you did, it would look something like...



Ext.override(Ext.data.AjaxProxy, {
doRequest: function(operation, callback, scope) {
var writer = this.getWriter(),
request = this.buildRequest(operation, callback, scope);

if (operation.allowWrite()) {
request = writer.write(request);
}

Ext.apply(request, {
headers : this.headers,
timeout : this.timeout,
scope : this,
callback : this.createRequestCallback(request, operation, callback, scope),
method : this.getMethod(request),
disableCaching: false // explicitly set it to false, ServerProxy handles caching
});

this.lastRequest = Ext.Ajax.request(request);

return request;
},

abort: function() {
Ext.Ajax.abort(this.lastRequest);
}
});
then you could do


if (store.loading) store.getProxy().abort();