I have already a few stores instanciated. But at a certain point, I'd to add a HTTP header in all of them. How can I do that, with ExtJS 4 ?
-
1can you please post some code? – leeny Nov 08 '11 at 06:15
-
I don't have any specific code for this issue. It's just a question about common json store. If it was not instanciated though, I would override Ext.Ajax.defaultHeaders. But it's already instanciated, and I'd like to add a header. It seems there is no way to do so... – TigrouMeow Nov 08 '11 at 08:30
3 Answers
Assuming that you are using an ajax proxy, you could update the headers
property on the stores in question. Looking at the code it'll apply whatever is in there as the headers.
A more involved solution would involve overriding the doRequest
function to do whatever suited you.

- 8,336
- 1
- 28
- 30
-
It seems headers is only a config option. Once the store (and the proxy) initialized, I got the proxy from the store, updated "headers" (which is undefined), and that does nothing :( Did you ever try updating headers after that the proxy was initialized? – TigrouMeow Nov 08 '11 at 09:43
-
Haven't done it, but take a look at the source: http://docs.sencha.com/ext-js/4-0/source/Ajax2.html#Ext-data-proxy-Ajax-cfg-headers ... you can see that at the point of `doRequest` it just uses the `headers` property on the proxy. Debug to make sure you're really setting it? – wombleton Nov 09 '11 at 01:21
-
Do you think this doRequest function is used by the stores? Probably not. – TigrouMeow Nov 27 '11 at 10:49
-
For me setting headers worked: I created a custom Proxy (which inherited from ajax proxy) and override the constructor to set headers. I called callParents method before anything in my constructor method. Hopefully this will help someone^^ – Francesco Belladonna May 23 '12 at 17:42
The answer provided by wombleton is close, but the key is that you have to set the headers property on the store's proxy, not on the store itself, e.g.:
Ext.StoreManager.lookup("MyStore").proxy.headers = { foo: "bar" }
The next time you load the store the specified headers will be sent with the request.

- 9,474
- 36
- 90
- 105

- 1,334
- 8
- 10
Don't pay attention to your headers being undefined, thats because the proxy has headers uninitialized, the default headers are in connection, but, at the time of building the request, your proxy (even implicit proxys) headers, wil be taken into acount, so you can do something like this:
Ext.apply(myStore.proxy.headers, {headerName:headerValue});
Kind regards

- 1,987
- 20
- 22
-
I tried but it's not working. The store exists already, and when it "loads" or anything it doesn't take the new header in account. – TigrouMeow Nov 27 '11 at 10:47
-
Mmm, but it works using: Ext.Ajax.defaultHeaders = { 'X-Something': value }; – TigrouMeow Nov 27 '11 at 11:06