1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    5
    Vote Rating
    0
    semanticart is on a distinguished road

      0  

    Default Answered: How can I set global http headers for ajax requests?

    Answered: How can I set global http headers for ajax requests?


    I want to send the device ID in every request to my server. What's the easiest way to globally set headers without regard to what store is being used (inline or a defined class)?

    I came up with this, which works but feels rather hacky:

    Code:
    Ext.override(Ext.data.proxy.Ajax, {
      constructor: function(config) {
        config.headers || (config.headers = {});
        config.headers.uuid = 'SOME-EXAMPLE-UUID';
        return this.callOverridden([config]);
      }
    });
    I'm new to Sencha Touch, so any help is appreciated.


  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,798
    Answers
    3467
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    5
    Vote Rating
    0
    semanticart is on a distinguished road

      0  

    Default


    Thanks, I ended up doing this:

    Code:
    Ext.Ajax.on('beforerequest', (function(klass, request) {  return request.headers.uuid = 'SOME-EXAMPLE-UUID';
    }), this);
    Obviously I'll be using a function instead of hard-coding the uuid. Thanks again for the help, let me know if there's yet a better way.

  4. #4
    Sencha User
    Join Date
    Nov 2012
    Location
    India
    Posts
    25
    Vote Rating
    0
    shri_iitk is on a distinguished road

      0  

    Default set default headers

    set default headers


    This is what I use:

    Code:
    Ext.Ajax._defaultHeaders = {
                'token' : (loggedInUserToken == undefined) ? "" : loggedInUserToken,
                'Accept': 'application/json',
                'Authorization': 'Basic YX5iOmM='
            };

  5. #5
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    498
    Answers
    25
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    I prefer semanticart's way as it's always best to avoid modifying private variables. The former way should be more future-proof.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi