Daniele Testa
Daniele Testa

Reputation: 1667

Altering the URL on all ajax-calls from ExtJS

I am using Ext.Ajax.request() in lots of places in my ExtJS Application.

Is there a way to have a function run just before the Ajax-call is made, that can alter the URL just before it is sent?

I would like to add an extra query-string to all of my Ajax requests dynamically.

I do not want to go and edit all my Ajax-calls manually.

Upvotes: 3

Views: 2393

Answers (2)

Reimius
Reimius

Reputation: 5712

This is what we do:

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;
        if(!options.params)
            options.params = {};
        options.params.ext_request = true;

        return me.callOverridden(arguments);
    }
});

Connection is the class that Ext.Ajax inherits from.

Upvotes: 4

phatskat
phatskat

Reputation: 1815

Ext.Ajax has a beforequest event that fires before any request happens:

Ext.Ajax.on('beforerequest', function(conn, options, eOpts) {
    console.log('The options parameter contains the options');
    console.log(' going to the request method');
});

Upvotes: 4

Related Questions