首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > JavaScript > Ajax响应缓存JavaScript

Ajax响应缓存JavaScript

  • 资源大小:3.58 kB
  • 上传时间:2021-06-29
  • 下载次数:0次
  • 浏览次数:1次
  • 资源积分:1积分
  • 标      签: javascript 缓存 ajax 响应

资 源 简 介

Enables short-term ajax response caching in user"s browser using JavaScript. basic example: lets say we have this code (below), ajax request is sent to server every time we want to obtain data. Which is not always necessary and results in more process time for server, more bandwidth usage and delay while waiting for the response. $.ajax({ url: ajax_path, type: "GET", data: viewData, dataType: "json" success: function(response) { // update website update_website(response); }, error: function(xhr) { // handle errors handle_errors(xhr); },}); We can transform it to: if(cache.on){ var cachedResponse = cache.get(ajax_path, [viewData]); if(cachedResponse !== false) { // update website update_website(cachedResponse); // We just avoided one ajax request return true; }}$.ajax({ url: ajax_path, type: "GET", data: viewData, dataType: "json" success: function(res

相 关 资 源

您 可 能 感 兴 趣 的

同 类 别 推 荐

VIP VIP