0
我無法嘗試將標題添加到我已有的同步方法中。我想我會把它們作爲一個關鍵:對象,或者將它們設置爲選項;這兩種方法我看到在不同的職位。這兩種嘗試都不會在chromes網絡選項卡或我的api日誌中顯示標題。主幹同步,添加標題以同步
我也試圖通過jquery的設置可全局設置此:
$.ajaxSetup({
headers: { 'x-my-custom-header': 'some value' }
});
任何幫助將不勝感激!
作爲選項散列。
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);
},
作爲params鍵:
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);
},