2

The problem: I am using Jquery UI tabs. The tabs display data that is stored in a database. Lets say the tabs are on home.com. In order to edit data in the database, you are taken to a new page where you can edit the data (e.g home.com/edit). Once you go back to home.com the new data should be displayed. This is the case in google chrome and firefox, but not in Internet explorer.

The weirdness: I can set $.ajaxSetup({cache:false}); and now the data is reloaded. Which makes me think it is an ajax issue with internet explorer (ignoring get requests). The trouble is that I don't want the cache to be set to false. I only want the tab to load once when the tab is click(styles, javascript, data, etc. do not need to be reloaded.). i.e. the tab should only be reloaded when you go to a different page and then come back, not each time you click the tab.

Also, When all of the IE windows are closed, and then navigate back to home.com, the updated data is displayed. Data is being refreshed on the site, but just not on pages where ajax calls are made. It seems like the behavior should be that ajax Get requests that are made should be ignored unless the whole page is refreshed, but the behavior appears to be that ajax Get requests are ignored unless the session is refreshed.

Hope that makes sense. Any help is greatly appreciated!

Here is an example of what the code would look like: html:

<div id='tabs'>
<ul>
<li><a href='Home.php?viewIsActive=true&tab=true'> Active </a></li>
<li><a href='Home.php?listAll=true&tab=true'> List All </a></li>
</ul>
</div>

Javascript:

$("#tabs").tabs();

Switching between tabs should cache, but reloading the page should reload the tabs as well.

4

1 回答 1

2

想通了!

那里的大多数信息都说要使用 Jquery:

$.ajaxSetup({cache:false});

或 html 标头

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

问题是这两者都完全摆脱了缓存。在我的情况下,我只想关闭 ajax 缓存,并且只在页面重新加载时,而不是在页面内。

$.ajaxSetup({cache:false}); 将时间戳添加到 ajax 获取 url。麻烦的是每次点击标签,都会添加一个新的时间戳,让IE认为它是一个新的URL,并重新加载所有信息。

解决方案:将时间戳添加到服务器端。这样,每次重新加载页面并联系服务器时,都会有一个新的时间戳。但是当您在客户端单击时,IE 不会重新加载 url,因为它是相同的,并且只会在页面重新加载/导航离开和返回时发生变化。

php:

$time = time();
$tabs = "<div id='tabs'>
<ul>
<li><a href='Home.php?viewIsActive=true&tab=true&timeStamp=" . $time . "'> Active </a></li>
<li><a href='Home.php?listAll=true&tab=true&timeStamp=" . $time . "'> List All </a>    </li>
</ul>
</div>"

因此,对于您只想在每次页面刷新/导航时加载一次的 ajax 请求,请使用服务器端时间戳,对于您不想缓存的 ajax 请求,请使用 jquery 客户端时间戳。

于 2013-09-19T16:14:47.397 回答