0

I'm failing trying to add headers to my already working sync method. I figured i'd either pass them as a key: object, or set them in options; both methods I saw in different posts. Neither attempts surface the headers in chromes network tab, or my api logs.

I've also attempted setting this globally through jquery settings:

$.ajaxSetup({
    headers: { 'x-my-custom-header': 'some value' }
});

Any help would be much appreciated!!!

As options hash.

sync: function(method, model, options) {
          options.headers =  { 'X-Key-Whatever' :'Foobar' }
          // Default JSON-request options.
          var params = _.extend({
            type:         'GET',
            dataType:     'jsonp',
            url:      model.url(),
            processData:  false,
            jsonpCallback: 'abcShowSomething',
            cache: true
          }, options);

          // Make the request.
        return $.ajax(params);
        },

As params key:

sync: function(method, model, options) {

          // Default JSON-request options.
          var params = _.extend({
            type:         'GET',
            headers: { 'X-Key-Whatever' :'Foobar' },
            dataType:     'jsonp',
            url:      model.url(),
            processData:  false,
            jsonpCallback: 'abcShowSomething',
            cache: true
          }, options);

          // Make the request.
        return $.ajax(params);
        },
jahrichie
  • 1,215
  • 3
  • 17
  • 26

1 Answers1

0

I figured this out after 24-48 hours of research. This is a JSONP request, and therefore it is impossible to pass headers. [See1

Community
  • 1
  • 1
jahrichie
  • 1,215
  • 3
  • 17
  • 26