1.引入jquery库, 在发送请求时, 将xhrFields的withCredentials设为true
示例代码如下:
$.ajax({ url: 'http://example.com/api/some_resource', type: 'GET', dataType: 'json', xhrFields: { withCredentials: true }, success: function(data) { console.log(data); } });
2.在backbone的sync方法中, 将xhr的withCredentials设为true
示例代码如下:
var originalSync = Backbone.sync; Backbone.sync = function(method, model, options) { options.xhrFields = { withCredentials: true }; return originalSync(method, model, options); };
注:CORB的阻止机制通常出现在跨域请求时, 通过withCredentials设置对XHR对象进行配置, 使其可以随同凭证一起发送。
上一篇:Backbone.js在哪些场景下使用最为合适?是否适合用于与Canvas相关的应用?
下一篇:Backbone.js中的model.set和model.get有哪些用法和实际应用场景?如何正确使用这两个方法来管理模型数据?