skip to Main Content

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


  1. 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 a beforerequest event, check the documentation here.

    Find a place in your application that runs once, for example in your Application.js. Add this:

    Ext.Ajax.on('beforerequest', function(conn, options, eOpts) {
    
    });
    

    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 in options.url and the parameters within options.params.

    So you can add you extra param like:

    options.params.myNewParam = 'New Param';
    

    (You can do many other things here, for example you can cancel the request with return false; etc.)

    Login or Signup to reply.
  2. Like this.

    Ext.define('ModernApp.overrides.Ajax', {
        override: 'Ext.data.proxy.Ajax',
        extraParams: {
            myNewParam: 'New Param'
        },
    });
    

    That way you will overwrite everywhere you are using a proxy.Ajax

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search