【问题标题】:ember.js RESTAdapter: prevent caching in IE9ember.js RESTAdapter:防止在 IE9 中缓存
【发布时间】:2015-09-10 12:32:30
【问题描述】:
我的 ember cli 应用程序使用 RESTAdapter。在 IE9 中,ajax 调用是从缓存中重用的,因此不会反映数据更改。 Chrome 等总是正确调用服务器。
我知道这是 IE9 的常见问题。在其他应用程序(不是 ember)中,我只是将 ?_=timestamp 添加到 ajax 调用中。
如何在 ember cli 中做类似的事情?
【问题讨论】:
标签:
ajax
rest
internet-explorer
ember.js
【解决方案1】:
为您的适配器覆盖 buildURL 方法。
应用程序/适配器/应用程序.js:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
buildURL(modelName, id, snapshot, requestType, query) {
const now = Date.now();
if (query === undefined) {
return this._super(modelName, id, snapshot, requestType, query) + '?_' + now;
}
query._ = now;
return this._super(modelName, id, snapshot, requestType, query);
}
});
这将导致:
this.store.findAll('thing');
// REQUEST http://api.com/things?_1441892715766
this.store.query('thing', { something: true });
// REQUEST http://api.com/things?_=1441892783338&something=true
【解决方案2】:
在我的应用程序控制器的 init-function 中,我添加了:
$.ajaxSetup({
cache: false
});
这样就可以了。