AJAX中使用GET的时候,为什么每次都读取缓存的数据呢?
就是输出的内容改变了,但输出还是以前的数据,求高手解答!
<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>xmlhttp</title>
</head>
<script language="javascript">
function initxmlhttp()
{
var xmlhttp
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp=false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
return xmlhttp;
}
function readcontent()
{
var xmlhttp=initxmlhttp();
var showcontent=document.getElementById("showcontent");
var url="readfile.php";
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Cache-Control","no-cache");
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
showcontent.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
function writecontent()
{
var xmlhttp=initxmlhttp();
var content=document.forms[0].content.value;
var showcontent=document.getElementById("showcontent");
var url="writefile.php";
var poststr="content="+content;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(poststr);
xmlhttp.onreadyStatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
showcontent.innerHTML=xmlhttp.responseText;
}
}
}
</script>
<body>
<hr>
<p>AJAX的测试</p>
<p>
<form>
<textarea name="content" cols="50" rows="10" id="content">
</textarea>
<br>
<input type="button" name="Submit" value="读取文本文件数据" onClick="readcontent()">
<input type="button" name="Submit2" value="将数据写入文本文件" onClick="writecontent()"><br>
</form><div id="showcontent"></div>
</p>
<hr>
</body>
</html>
?>
writefile.php
<?
file_put_contents('test.txt',$_POST['content']);
echo $_POST['content'];
?>
readfile.php
<?
echo file_get_contents("test.txt");
?>
test.txt
<?php
this is a ajax test
?>