Adding header to Ajax request
Asked Answered
U

4

13

How can I add a request header to an ExtJS ajax request?

I specifically want to add the header: accept-encoding to equal true.

Undertow answered 1/8, 2012 at 16:31 Comment(2)
You question is very unclear. Perhaps you can be more descriptive as for what exactly you're trying to achieve?Moron
@Moron I clarified it to my understanding of the question. Hopefully I didn't take too many liberties with it...Mcconnell
H
15

You can specify request headers like this:

Ext.Ajax.request({
    url: 'yourUrl',
    headers: {
        'accept-encoding': 'true'
    }
})​
Haha answered 1/8, 2012 at 22:36 Comment(3)
does this works also for loading stores (as a config of load at the same level as params ?)Frustule
Hi @code4jhon, you want something like this to set headers on a stores proxy: Ext.getStore('YourStore').proxy.headers = {'accept-encoding': 'true'}Haha
yeah, added config when defining the store. (config in the proxy obviously) thanks works fine.Frustule
M
5

Have you tried the headers config in the Ajax request:

Ext.Ajax.request({
    url: 'someURL',
    headers: {
        'accept-encoding': true
    }
});
Mcconnell answered 1/8, 2012 at 20:50 Comment(0)
P
5

If you want to add a header to all Extjs ajax requests:

Ext.Ajax.defaultHeaders = {
    'accept-encoding' : true
};
Pacificism answered 31/1, 2014 at 19:58 Comment(0)
B
3

With ExtJs 6. Ext.Ajax.defaultHeaders doesn't work. But using the following setter works

Ext.Ajax.setDefaultHeaders({
    'accept-encoding' : true
});
Balmy answered 7/2, 2019 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.