喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: ajax的缓存问题  
 
feifengxlq
注册会员
Rank: 2
一般会员


UID 30058
精华 0
积分 140
帖子 144
金钱 140 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-7-14
来自 广州
状态 离线
[广告]: q m
ajax的缓存问题

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==&& 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==&& 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
?>




PHP面对对象
2006-2-28 10:08 AM#1
查看资料  访问主页  发短消息  QQ  顶部
 
feifengxlq
注册会员
Rank: 2
一般会员


UID 30058
精华 0
积分 140
帖子 144
金钱 140 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-7-14
来自 广州
状态 离线
[推荐阅读] 认为对模版系统比较了解的请进帮忙解决我的疑惑
自己顶下先~



PHP面对对象
2006-2-28 11:17 AM#2
查看资料  访问主页  发短消息  QQ  顶部
 
唠叨 (唠叨)
版主
Rank: 7Rank: 7Rank: 7
版主



UID 9955
精华 0
积分 1479
帖子 1546
金钱 1479 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2001-10-27
状态 离线
[推荐阅读] [求助]Zend studio 如何直接插入php标签?
这个现象只发生在ie中
你需要输出禁用缓存的头
2006-2-28 11:29 AM#3
查看资料  Blog  发短消息  顶部
 
feifengxlq
注册会员
Rank: 2
一般会员


UID 30058
精华 0
积分 140
帖子 144
金钱 140 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-7-14
来自 广州
状态 离线
[推荐阅读] 请问post and get 传值最大是多少KB
用xmlhttp.setRequestHeader("Cache-Control","no-cache");控制不行吗?



PHP面对对象
2006-2-28 11:40 AM#4
查看资料  访问主页  发短消息  QQ  顶部
 
feifengxlq
注册会员
Rank: 2
一般会员


UID 30058
精华 0
积分 140
帖子 144
金钱 140 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-7-14
来自 广州
状态 离线
[推荐阅读] Php5 命令行执行下的错误...


QUOTE:
最初由 唠叨 发布
[B]这个现象只发生在ie中
你需要输出禁用缓存的头 [/B]
恩,的确是,在firefox下不会出现~

但在IE中有没有解决的方法呢?




PHP面对对象
2006-2-28 11:43 AM#5
查看资料  访问主页  发短消息  QQ  顶部
 
唠叨 (唠叨)
版主
Rank: 7Rank: 7Rank: 7
版主



UID 9955
精华 0
积分 1479
帖子 1546
金钱 1479 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2001-10-27
状态 离线
[推荐阅读] 招聘php程序[上海]
反了,在readfile.php中

<?php
header 
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");// always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");                          // HTTP/1.0
?>
2006-2-28 11:46 AM#6
查看资料  Blog  发短消息  顶部
 
feifengxlq
注册会员
Rank: 2
一般会员


UID 30058
精华 0
积分 140
帖子 144
金钱 140 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-7-14
来自 广州
状态 离线
[推荐阅读] 非网管创业,刚买了台服务器,应该装什么软件?谢谢!
GOOD!谢谢斑竹了



PHP面对对象
2006-2-28 12:24 PM#7
查看资料  访问主页  发短消息  QQ  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.029790 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP