Passing Custom Headers to Ajax request on Select2
This is how I fixed sending auth token. Just add this as Select2 ajax param;
transport: function(params){ params.beforeSend = function(request){ request.setRequestHeader("Authorization", 'OAuth ' + api_access_token); }; return $.ajax(params);},
Taken from select2's demo page:
Select2 will pass any options in the ajax object to jQuery's $.ajax function, or the transport function you specify.
Using JQuery 2+, I was able to successfully set OAuth 2.0 and Content-Type headers.
ajax: { headers: { "Authorization" : "Bearer "+Cookies.get('accessToken'), "Content-Type" : "application/json", },}
another option:
ajax: { url: '/api/Part', params: { headers: { "Authorization": "XXX" } }, ...}