ajax的缓存问题
悬赏分:20 -
2007年08月18日
AJAX中使用GET的时候,为什么每次都读取缓存的数据呢?
就是输出的内容改变了,但输出还是以前的数据,求高手解答!
[php]
xmlhttp
<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>
AJAX的测试
[/php]
writefile.php
[php]
<?
file_put_contents('test.txt',$_POST['content']);
echo $_POST['content'];
?>
[/php]
readfile.php
[php]
<?
echo file_get_contents("test.txt");
?>
[/php]
test.txt
[php]
this is a ajax test
[/php]
提问者:feifengxlq 08-18 11:11