在jQuery ajax中不使用缓存



我在jQuery Ajax中有这个GET,我需要将它转换为Fetch。我的问题是cache: falsecache: "no-store"在header参数中是一样的?Ajax调用

function ajaxLogoutDetailsApi() {
$.ajax({
type: "GET",
url: "OIDCGetLogoutDetails",
async: false,
cache: false,
data: "json",
success: function (data, status, xhr) {
data = data.replace('/*', '');
data = data.replace('*/', '');
var dataJson = JSON.parse(data);
if (dataJson.logoutUrl != null) {
document.location.href = dataJson.logoutUrl;
}
},
error: function (xhr, status, err) {
console.log("error in ajaxLogoutDetailsApi");
}
});
}

获取电话:

function ajaxLogoutDetailsApi() {

const endpoint = 'OIDCGetLogoutDetails';

fetch(endpoint, {cache: "no-store"})
.then(json => {
const updated = json
.replace('/*', '')
.replace('*/', '');
const data = JSON.parse(updated);
if (data.logoutUrl) {
window.location.href = data.logoutUrl;
}
})
.catch(error => {
console.error('Error:', error);
});
}

From the docs

cache(默认:true, false对于数据类型'script'和'jsonp')类型:布尔

如果设置为false,它将强制请求的页面不被缓存浏览器。注意:将缓存设置为false只会正确工作HEAD和GET请求。通过附加"_={timestamp}"到得到参数. 的其他类型不需要此参数请求,除非在IE8中,当POST向已经存在的URL发出时

最新更新