Caching jsonp callback parameter when doing a backbone fetch

戏子无情 提交于 2019-12-11 23:46:32

问题


What is the correct way to cache this callback value when doing a backbone fetch? Have tried overiding the fetch function and setting

options.cache = true;

but no avail.

Ideally we want to continue using fetch, and not write a custom ajax call. The below is an example of the callback parameter that is being appended. I need this to be the same return value each time, i.e so it's acting as a cache.

&callback=jQuery1111042059096531011164_1421344480838&_=1421344480840

If more detail is needed please let me know,

Many thanks.


回答1:


You could use the local storage

if (!myData) {
  myCollection.fetch({
     success: function( data ) {
       localStorage.setItem('myData', JSON.stringify(data));
     }
  });
} else {
  myCollection.set(myData);
}



回答2:


FYI.

The solution that appears so far to have worked was to not override the fetch but override the sync and hardcode a string as the jsonPCallback such as below.

sync: function(method, model, options){
  options.dataType = this.SYNC_METHOD;
  options.cache = true;
  options.jsonp = 'callback';
  options.jsonpCallback = "onNowCallback";
return Backbone.sync(method, model, options);}


来源:https://stackoverflow.com/questions/27981774/caching-jsonp-callback-parameter-when-doing-a-backbone-fetch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!