Skip to content

Instantly share code, notes, and snippets.

@dostanko
Created June 7, 2013 13:05
Show Gist options
  • Save dostanko/5729104 to your computer and use it in GitHub Desktop.
Save dostanko/5729104 to your computer and use it in GitHub Desktop.
This code allows to intercept ajax requests in Sencha application. It's good base to emulate all the backend for JavaScript client, make it dynamic, add intellect to it, response with delay, and do not touch application code at all. Just include this and relative code.
Ext.require(["Ext.data.JsonP", "Ext.Ajax", "Ext.util.DelayedTask", "Localresponse.response"], function(){
Ext.merge(Ext.Ajax , {
request: function(params){
var serviceId = params.url.match( /\/([^\/\?]+)?\?/ ).pop().split("-").join("_");;
if (undefined !== Localresponse.responses[serviceId]) {
var delay = 500;
if (undefined !== Localresponse.responses[serviceId + "_delay"]) {
delay = Localresponse.responses[serviceId + "_delay"].call();
};
var delayedCallback = Ext.create('Ext.util.DelayedTask', function() {
var response = Localresponse.responses[serviceId].apply(this,[params]);
Ext.callback(params.callback, params.scope || window, [response, true, {responseText: Ext.encode(response)}]);
});
delayedCallback.delay(delay);
} else {
alert("can't process ajax responce " + serviceId);
};
}
});
});
@ErikaBarre
Copy link

in app.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment