ajax加上随机数可以强制刷新网页

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="button" value="获取数据">
<div></div>
<script src="../jquery.js"></script>
<script>
$(function(){
$("input[type=button]").click(function(){
$.ajax({
url: '../php/08.php?' + Math.random(),
type: 'get',
timeout:1000,//听架构师的
data: {param1: 'value1'},
success:function(data){
// alert(data);
$("div").text(data);
},
// 捕捉错误
/*error:function(jqXHR,textStatus,errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
if(errorThrown == "Not Found"){
alert("你请求的地址不存在");
}
if(textStatus == "timeout"){
alert("请求超时");
}
}*/
})
});
// 不管是什么错统统都提示这一个
$(document).ajaxError(function(event, xhr, settings, thrownError) {
alert("请求发生错误");
});
})
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/niuniuniu/p/6378246.html