解决方案:
由于低版本的IE浏览器发现请求的地址和上次请求地址没有发生变化时,会自动默认加载上次的缓存。为解决此问题,我们在请求的地址后面,通过random函数拼接一个随机数。
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content="width=device-width, initial-scale=1.0">
<Meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<style>
</style>
<body>
<button id='btn'>发送Ajax请求</button>
<script>
var btn =document.getElementById('btn');
btn.onclick=function(){
//1.创建Ajax对象
var xhr=new XMLHttpRequest();
//2.配置Ajax对象
//xhr.open('get','http://localhost:3000/cache');
xhr.open('get','http://localhost:3000/cache?t='+ Math.random());
//3.发送请求
xhr.send();
//4.获取服务器端响应的数据
//低版本浏览器不支持onload事件
xhr.onreadystatechange=function(){
if(xhr.readyState==4 && xhr.status==200){
alert(xhr.responseText);
}
}
//解决方案:
// 在请求地址的后面添加请求参数,保证每次请求中的请求参数的值不相同
}
</script>
</body>
</html>
<!--
Ajax状态码: 表示Ajax请求的过程状态,Ajax对象返回,xhr.readyState==4为正常
Http状态码:表示请求的处理结果,是服务端返回,xhr.status==200为正常
-->
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。