【发布时间】:2020-03-18 08:52:18
【问题描述】:
我有一个问题,model.save 没有通过我的跨源请求发回 cookie,但Ext.Ajax.request 发回 cookie 没有问题。在我们的本地开发工作中,我们覆盖所有 Ajax 请求(包括模型操作)上的 beforerequest 以设置 withCredentials = true 和 useDefaultXhrHeader = false,这有助于正常 Ext.Ajax.request 上的 CORS。
据我了解,拥有ajax 类型的代理类似于执行Ext.Ajax.request,这很明显,因为model.save 命中了之前的请求(您将在下面的示例中看到这一点)。您还会在示例中注意到 model.save 首先发送一个 OPTIONS 调用,然后再不跟进 POST(但这很可能是因为服务器)......无论哪种方式,OPTIONS 而不是 POST 似乎有点鱼腥味。
这是example:
Ext.Ajax.on({
beforerequest: function (conn, options, eOpts) {
console.log('here', conn, options)
options.useDefaultXhrHeader = false;
options.withCredentials = true;
}
});
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: ['test'],
proxy: {
type: 'ajax',
url: 'https://docs.sencha.com'
}
});
var model = Ext.create('MyModel');
// This will fire off an OPTIONS call and not send the cookies
model.save();
// This will fire off with the POST and send the cookies
Ext.Ajax.request({
url: 'https://docs.sencha.com',
method: 'POST'
});
有没有办法让model.save把cookies发送到跨域?
【问题讨论】:
标签: javascript cookies extjs cross-domain extjs6