【发布时间】:2014-06-08 20:39:46
【问题描述】:
我未能尝试将标头添加到我已经工作的同步方法中。我想我要么将它们作为 key: 对象传递,要么将它们设置在选项中;我在不同的帖子中看到了这两种方法。既没有尝试显示 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);
},
作为参数键:
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);
},
【问题讨论】:
标签: jquery backbone.js http-headers sync request-headers