代码与范例:
$.get({
url: GetUrl,
// 方法1 - 使用 POST 方法
type: 'POST',
// 方法2 - 禁用 cache
cache: false,
// 方法3 - 修改参数
dataType: 'json'?id=+Math.random(),
data: {
Id: parameterId
}
}).done(function (data) {
});
}
方法4 – 页面 meta tag
<meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'>
说明:Ajax 调用存在缓存,再次以相同参数调用时可能会直接调取先前结果,造成结果错误。可以用以上四种方式回避该问题。