1
我想不通,爲什麼我的劍道自動完成構件不是在請求到服務器發送的授權頭:劍道自動完成授權頭
var dataSource = new kendo.data.DataSource({
type: 'odata',
serverFiltering: true,
transport: {
read: {
url: myApiUrl,
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', myAuthorizationValue);
}
}
}
});
$('#myAutocompleteField').kendoAutoComplete({
dataTextField: 'fieldName',
filter: 'contains',
minLength: 3,
dataSource: dataSource
});
當我檢查在開發工具的服務器響應,我從服務器獲取401 Unauthorized
錯誤。查看請求頭,我根本沒有看到Authorization
屬性。
我需要做些什麼才能使授權標頭包含在請求中?
更新:
我繼續探討這個問題。如果我只是在Kendo DataSource參數中使用與transport.read
相同的對象進行典型的$.ajax
請求,它會發送這些頭並且我會得到一個成功的響應。
$.ajax({
url: myApiUrl,
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', myAuthorizationValue);
},
success: function(res) {
console.log('success!');
console.log(res);
}
});