I have a bigger application written with ExtJs 7. Now I need to add an extra-Parameter to all ajax-calls and ajax-store-calls from a certain point on.
To change all ajax-calls and all stores would be a lot of work, so the idea is to define an override or prototype, and all calls done after that should use the new parameter.
I tried:
Ext.override(Ext.Ajax, { extraParams: {myNewParam:'New Param' }});
and
Ext.Ajax.extraParams =
{ myNewParam:'New Param'
};
and
Ext.Ajax.prototype.extraParams =
{ myNewParam:'New Param'
};
but myNewParam is either not transmitted or I get JavaScript errors.
What is the correct way to do it?
2
Answers
I am not sure this is what you need but this is one possibility.
You can use an event listener attached to
Ext.Ajax
that is executed before every request. There is abeforerequest
event, check the documentation here.Find a place in your application that runs once, for example in your
Application.js
. Add this:You need to determine somehow wether you need the new extra param for this particular request.
Within the above function, all request options are in the
options
parameter. For example you have the URL inoptions.url
and the parameters withinoptions.params
.So you can add you extra param like:
(You can do many other things here, for example you can cancel the request with
return false;
etc.)Like this.
That way you will overwrite everywhere you are using a proxy.Ajax