View Full Version : Adding "Call Source" to Each Ajax Call

12 Apr 2018, 12:43 PM
I have three different areas in my application that can modify hours. They all use the same grid, store, and model (but different instances) along with the same url on the backend. I am trying to implement a way to add a parameter to the ajax calls, so the backend knows which area of the application that the call came from.

I have attempted the following:
1. Overriding request function in Ext.data.Connection

Ext.data.Connection.override({ //add an extra parameter to the request to denote that ext ajax is sending it
request: function(options){
var me = this;
options.params = {};
options.params.location = 'location 1';

return me.callOverridden(arguments);
Result: I couldn't figure out a way to find the module that made the call.

2. Adding the following to the controllers init of the controllers

Ext.Ajax.on('beforerequest', function(conn, options) { if(!options.params)
options.params = {};
options.params.location = "location 1";
Result: Every call was sending the same location even if it was a different area

23 Apr 2018, 1:06 AM
1> Since you have used override, I understand that you do not have access to change the ajax code present in those 3 different flows of your application, is that right?
Your override will be only at one location and applies to all of the flows so you will always receive the same parameter ("Location 1").

2> If the statement one is true, you can handle this by use of global variables. create a getter/setter method which acts on a global variable in your controller. Call this setter method after the each of the 3 ajax calls which are present at different location and set the right value, for instance say 'Loc1'/'Loc2' or 'Loc3'. In your override , call getLocation which will return you either Loc1 2 or 3 based on the recent ajax call made.

I do not have the complete picture of your code flow so this is the best I could come up with at the moment. Hope this helps.