<?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/"
				  >
<channel>
<title><![CDATA[Saturn's Weblog - 标签：ajax]]></title>
<link>http://www.cnsaturn.com/tag/ajax</link>
<description><![CDATA[Saturn's weblog, STBlog官方站点]]></description>
<language>zh-CN</language>
<pubDate>Thu, 09 Sep 2010 19:35:02 -0400</pubDate>
<item>
<title><![CDATA[AJAX Sudoku: 网页版的超炫数独游戏]]></title>
<link>http://www.cnsaturn.com/posts/a-web-based-ajax-sudoku-game</link>
<pubDate>Fri, 05 Jun 2009 21:34:00 -0400</pubDate>
<description><![CDATA[<p>喜欢玩智力游戏的同学对数独这个游戏一定不陌生，但大多数情况下，大家玩得都是手机版、单机版和Flash版，很少有非Flash网页版的数独游戏。</p> <p>今天在网上闲逛找项目灵感时，发现了一个基于AJAX的网页版数独游戏<a href="http://deepliquid.com/projects/sudoku/" target="_blank">AJAX Sudoku</a>。</p> <p>整个游戏基于<a href="http://jquery.com">jQuery</a>+PHP+<a href="http://ostermiller.org/qqwing/" target="_blank">qqwing</a>制作，不过这个游戏将IE浏览器彻底鄙视了一回：IE<strong>浏览器用户使用时将会出现很多问题，所以，要获得最佳游戏体验，最好使用Firefox，Opera，Safari或者Chrome中的一款</strong>。</p> <p style="text-align: center"><img src="http://www.cnSaturn.com/uploads/Sudoku.JPG" alt="网页AJAX版数独游戏截图" title="网页AJAX版数独游戏截图" width="400" height="220" /></p> <p>游戏方法非常简单：</p> <p>选定一个方格之后，按照数独游戏规则，通过电脑键盘输入一个数字即可。</p> <p>游戏网址：<a href="http://deepliquid.com/projects/sudoku/">http://deepliquid.com/projects/sudoku/</a></p>]]></description>
<author><![CDATA[Saturn]]></author>
<guid isPermaLink="true" >http://www.cnsaturn.com/posts/a-web-based-ajax-sudoku-game</guid>
</item>
<item>
<title><![CDATA[防止AJAX动态结果在前端页面缓存的方法]]></title>
<link>http://www.cnsaturn.com/posts/prevent-ajax-from-caching-data-in-front-page</link>
<pubDate>Sun, 24 May 2009 02:18:00 -0400</pubDate>
<description><![CDATA[<p>
 在利用AJAX从后台程序提取数据，然后在前端页面显示出来的过程中，我们经常会碰到<a target="_blank" title="Ajax不运行解决一例：动态页的客户端网页缓存" xhref="http://www.auiou.com/relevant/00000388.jsp">AJAX提取的数据被缓存</a>，导致结果异常的问题。</p>
<p>
 具体原因是因为AJAX依赖于JavaScript，而浏览器会自动将JavaScript代码和文件数据缓存在客户端，这有利于用户下次访问时页面的快速下载和解析。</p>
<p>
 要解决数据被缓存，大概有两种做法。</p>
<p>
 第一种，是在客户端进行，在AJAX发送请求到后台数据处理页面的URL上加一个<strong>随机字符串</strong> 即可。这样一来，浏览器会认为AJAX发出的HTTP请求每次都不同（URL不同），从而每次都重新请求。具体做法如下：</p>
<pre class="brush:js;">
xmlHttp.open(&quot;GET&quot;, &quot;ajax.php?r=&quot;+new Date().getTime(), true);</pre>
<p>
 既然是随机字符串，还可以使用：+math.random()，只要保持字符串随机即可。</p>
<p>
 另外一种是在服务器端进行。具体做法是修改HTTP头信息，手动设置让其过期。下面以PHP为例说明：</p>
<pre class="brush:php;">
header (&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;); // Date in the past
 header (&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;); // always modified
 header (&quot;Cache-Control: no-cache, must-revalidate&quot;); // HTTP/1.1
 header (&quot;Pragma: no-cache&quot;); // HTTP/1.0</pre>
<p>
 其他语言，比如ASP，J2EE，做法与此非常类似。</p>
<p>
 通常情况下，我们只需要选其以上两种方法的其中一种即可。</p>]]></description>
<author><![CDATA[Saturn]]></author>
<guid isPermaLink="true" >http://www.cnsaturn.com/posts/prevent-ajax-from-caching-data-in-front-page</guid>
