Ajax Tips - Avoid the cache effect in IE

本文介绍了一种在使用GET请求时防止Internet Explorer浏览器缓存数据的方法。通过在URL中添加一个不断变化的参数如当前时间戳或随机数,可以确保每次请求都能获取到最新的数据。此外,还提供了一个使用jQuery实现的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If you use a GET method to send an asynchronous request to server side code,

if you don't do anything Internet Explorer will cache locally your request, so obviously you won't have the latest result in your response.

 

So instead of scripting something like this in Javascript (unless you use a POST method):

var url = "getCustomer.do?cm=S001"

use this:

var url = "getCustomer.do?cm=S001"  + " & nocache="+ new Date().getTime();

 

This will force IE to show a fresh version of your request all the time because this request will put in a constantly changing variable in the URL such as date with seconds in Internet Explorer.

or

var url = "getCustomer.do?cm=S001"  + " & random="+math.random()    


Firefox doesn't seem to have this problem apparently.

we adopt jquery tech to get JSON response from server side, but only GET method is provided by this method $.getJSON(),

so we have to do more things to resolve IE cache issue as follows.

$.getJSON("../ajax/enquirecommcode.do"
, {"cmCode"
 : cmCode,"cpcmCode"
:cpcmCode,"nocache"
:Date()}

$.getJSON("../ajax/enquireoutrightleg.do" ,{"commCode" : commCode,"nocache" :Date()}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值