JS / AJAX浏览器的缓存问题 [英] JS/AJAX browser caching issue

查看:111
本文介绍了JS / AJAX浏览器的缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作的网上商店用计算器来计算您的贷款。我需要这方面的一些新的见解......想象一下这种情况:

I am working on an eshop with a calculator to calculate your loan. I need some fresh insight on this... imagine this situation:

  1. 在用户点击按钮,它会做一个POST请求(jQuery的)之一,并填写所需的数据。
  2. 在用户点击添加到购物车并进入购物车
  3. 在用户点击返回按钮(浏览器)
  1. User clicks on one of the buttons it will do a POST request (jQuery) and fill the required data.
  2. User clicks add to cart and goes to cart
  3. User clicks back button (browser)

加载页面时,服务器填充数据计算器(默认值),但经过对其做,从浏览器的缓存填充JS数据和一个有趣的事情发生了。得到的数据相结合,当用户添加该产品到他的车,他会得到错误的,但是有效的价格。有效的部分是服务器填补,其余来自于缓存中。

Page is loading, server is filling the data in the calculator (default), BUT after its done, browser fills the JS data from cache and a funny thing happens. The data gets combined and when user adds the product to his cart he will get wrong, but valid price. Valid part is what server fills and the rest comes from cache.

我已经使用元标记,以prevent缓存试过,我已经告诉了jQuery的不可以缓存POST请求,甚至在我响应,我有说的多个头 - DO不缓存。可是偏偏POST数据被缓存的,我不知道如何将其关闭或刷新或任何...当我看那个回来的JSON数据的报头,标题过期设置到2099年为止,即使我已经说应该是一年过去。除此之外,我真的不知道这可能是导致这个问题。

I have tried using meta tags to prevent caching, I have told jquery to not cache the POST request and even in my responder, I have multiple headers that say - DO NOT CACHE. Yet still the POST data gets cached and I have no idea how to turn it off or refresh it or whatever... When I look at the headers that come back with the json data, header expires is set to year 2099, even though I have said it should be a year from past. Apart from that, I really dont know what could be causing this issue.

下面是响应者设置的标头,什么回来:

Here are the headers set in responder and what gets back:

 header("Expires: Mon, 26 Jul 1999 05:00:00 GMT" );
 header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
 header("Cache-Control: no-cache, must-revalidate" );
 header("Pragma: no-cache" );
 header("Content-type: text/x-json");

这回来(从萤火虫):

    Date         Fri, 17 Sep 2010 08:39:38 GMT
    X-Powered-By PHP/5.1.6
    Connection Keep-Alive
    Content-Length 126
    Pragma         no-cache
    Last-Modified Fri, 17 Sep 2010 08:39:38GMT
    Server         Apache
    Content-Type text/x-json
    Cache-Control no-cache, must-revalidate
    Expires         Mon, 26 Jul 2099 05:00:00 GMT

请注意:当我禁用缓存在浏览器preferences它就像一个魅力

Note: when I disable cache in browser preferences it works like a charm.

任何想法,欢迎!

编辑:

我已经试过了假前几个小时,但是这并不解决问题。说得简单,整个问题是,当用户点击后退按钮时,页面的不会刷新,但缓存的读取,或至少来自AJAX中的数据进行缓存,并得到填补。

I have tried the dummy few hours before, but that doesnt solve it. To put it simple the whole problem is that when user clicks back button, the page wont refresh, but its read from cache, or at least the data that came from ajax are cached and get filled.

因此​​,基本上,我需要当用户单击后退按钮刷新页面在一个巧妙的方法。请注意,cookie是不是一种选择,因为(也许一个很小的比例,但仍然)有些人不都饼干允许的。

So basically I need to refresh the page in a smart way when user clicks back button. Note that cookies are not an option, because (maybe a small percentage, but still) some people dont have cookies allowed.

推荐答案

解决一些带一点黑客,因为它看起来像纯浏览器的问题。

Solve it some with a little hack, since it looks like pure browser issue.

这篇关于JS / AJAX浏览器的缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆