在jQuery ajax中不使用缓存
我有jQuery ajax的速度,我需要将其转换为获取。我遇到的问题是缓存:false
与缓存相同:fetch中的标题参数中的“ no-code”
? 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);
});
}
I have this GET in jQuery Ajax and I need to convert it to Fetch. The question I'm having is that cache: false
is the same as cache: "no-store"
in header param in fetch?
Ajax call
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");
}
});
}
Fetch call:
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);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 docs
From the docs