php 发送restful请求,php – 将自定义HTTP标头传递给RESTful请求

Backbone将其XHR请求委托给jQuery / Zepto,这是您必须修改的内容.

最简单的解决方案可能是通过$.ajaxSetup和headers options提供默认选项

headers(added 1.5)

Default: {}

A map of additional header key/value pairs to send along with the

request. This setting is set before the beforeSend function is called;

therefore, any values in the headers setting can be overwritten from

within the beforeSend function.

你会这样设置:

$.ajaxSetup({

headers:{

X_REST_USERNAME: "admin@restuser",

X_REST_PASSWORD: "admin@Access"

}

});

或者您可以为每个请求传递其他选项,Backbone会将它们转发给jQuery:

var m = new Backbone.Model();

m.fetch({

headers:{

X_REST_USERNAME: "admin@restuser",

X_REST_PASSWORD: "admin@Access"

}

});

最后,您可以覆盖Backbone.sync以为每个请求添加标头:

Backbone.realsync = Backbone.sync;

Backbone.sync = function(method, model, options) {

options || (options = {});

options.headers = {

X_REST_USERNAME: "admin@restuser",

X_REST_PASSWORD: "admin@Access"

};

return Backbone.realsync.call(model, method, model, options);

};

var m = new Backbone.Model();

m.fetch();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值