Stiamo cercando di implementare Ajax caricamento dei dati remota in Select2: -Passing intestazioni personalizzate a richiesta Ajax su 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 };
}
}
};
Stiamo utilizzando AngularJS. Con ogni richiesta HTTP abbiamo impostato come predefinito il nostro Authtoken come intestazione. Ma in qualche modo non funziona in combinazione con la richiesta Ajax Select2. Nel codice sopra, il codice commentato sono i miei tentativi falliti.
La risposta accettata avrebbe potuto essere l'unica opzione nel 2012, ma oggi [questa risposta] (http://stackoverflow.com/a/28793936/ 971557) dovrebbe funzionare per tutti. –