2

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.

4

2 回答 2

4

Ext.Ajax有一个beforequest在任何事情发生之前触发的事件request

Ext.Ajax.on('beforerequest', function(conn, options, eOpts) {
    console.log('The options parameter contains the options');
    console.log(' going to the request method');
});
于 2013-07-24T20:29:57.293 回答
3

这就是我们所做的:

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 是 Ext.Ajax 继承自的类。

于 2013-07-24T20:30:07.123 回答