Search code examples
extjsextjs-mvcextjs5

How to set common request headers for every ajax request in ext5?


I have to set customized headers for every ajax request, is there a way to do this only once without having to config it manually in every ajax proxy.

proxy: {
   headers: {
      token: 'xyz' // this token that every proxy should contain to communicate with our remote server. 
   }
}

In jQuery i can accomplish this by using "ajaxPrefilter" like following:

jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
    jqXHR.setRequestHeader('token', 'xyz');
}

But i don't known how to do it properly in extjs, please help!


Solution

  • Ext.Ajax.setDefaultHeaders({
                'Accept':'application/json'
            });