<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>71街 &#187; 刷新</title>
	<atom:link href="http://www.71j.cn/archives/tag/%e5%88%b7%e6%96%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://www.71j.cn</link>
	<description>杜工的技术博客</description>
	<lastBuildDate>Fri, 16 Dec 2011 03:52:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>操作页面刷新后，数据不能及时更新</title>
		<link>http://www.71j.cn/archives/37</link>
		<comments>http://www.71j.cn/archives/37#comments</comments>
		<pubDate>Tue, 01 Sep 2009 10:15:38 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[刷新]]></category>
		<category><![CDATA[跳转]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=37</guid>
		<description><![CDATA[众所周知，刷新页面可以直接在html的head标签中使用如下代码： &#60;meta http-equiv=&#34;refresh&#34; content=&#34;1; URL=http://www.71j.cn&#34;&#62; 其中content中的数字1表示等待是时间(秒) 也可以使用php发送头消... ]]></description>
			<content:encoded><![CDATA[<p>众所周知，刷新页面可以直接在html的head标签中使用如下代码：</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;refresh&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1; URL=http://www.71j.cn&quot;</span>&gt;</span></pre></div></div>

<p>其中content中的数字1表示等待是时间(秒)</p>
<p>也可以使用php发送头消息：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:http://71j.cn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>甚至可以使用js中window.location.reload()方法，但是我们在开发过程中发现，因为浏览器或者CDN等带有的缓存机制会使页面刷新后，数据得不到刷新。</p>
<p>解决办法如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> autorefresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&amp;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> href<span style="color: #339933;">=</span>window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>href.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;t=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>href.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> s<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;?&quot;</span><span style="color: #339933;">;</span>
window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">+=</span>s<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;t=&quot;</span><span style="color: #339933;">+</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> href.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/t=[0-9]+/</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;t=&quot;</span><span style="color: #339933;">+</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>这样给url加上时间戳，可以有效解决本问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/37/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

