Passing Custom Headers to Ajax request on Select2
Posted
by
Sutikshan Dubey
on Stack Overflow
See other posts from Stack Overflow
or by Sutikshan Dubey
Published on 2012-10-30T07:55:52Z
Indexed on
2012/11/04
11:01 UTC
Read the original article
Hit count: 1969
We are trying to implement Ajax Remote data loading in Select2:-
$scope.configPartSelect2 = {
minimumInputLength: 3,
ajax: {
url: "/api/Part",
// beforeSend: function (xhr) { xhr.setRequestHeader('Authorization-Token', http.defaults.headers.common['Authorization-Token']); },
// headers: {'Authorization-Token': http.defaults.headers.common['Authorization-Token']},
data: function (term, page) {
return {isStockable: true};
},
results: function (data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
return { results: data };
}
}
};
We are using AngularJS. With each Http request we have set it's default to have our Authtoken as header. But somehow it is not working in conjunction with Select2 Ajax request. In above code, commented code are my failed attempts.
© Stack Overflow or respective owner