如何在获取请求中设置 cookie?
How Do I set a cookie in fetch request?
我对一个特定问题感到困惑。我正在尝试使用 fetch api 设置 cookie,但我无法这样做。
static deleteorder = (domain = "http://localhost:8080/pc", order) => {
let cooks = "JSESSIONID=AFAFWEEVV2323GG";
fetch(deleteorder, {
method: `GET`,
credentials: 'same-origin',
headers: {
"Content-type": `application/x-www-form-urlencoded`,
},
})
.then(res => {
console.log(res.status);
})
.catch(error => {
console.log(error);
});
};
}
When 函数运行并返回 200
但数据保持不变,这意味着顺序保持不变。你们中的一个可以阐明一些吗?我正处于学习 fetch api 的初学者阶段,因此非常感谢任何反馈。
Fetch()
只是发送当前文档的 cookie,所以只需将 cookie 添加到 document.cookie
。
static deleteorder = (domain = "http://localhost:8080/pc", order) => {
document.cookie = "JSESSIONID=AFAFWEEVV2323GG";
fetch(deleteorder, {
method: `GET`,
credentials: 'same-origin',
})
.then(res => {
console.log(res.status);
})
.catch(error => {
console.log(error);
});
};
我对一个特定问题感到困惑。我正在尝试使用 fetch api 设置 cookie,但我无法这样做。
static deleteorder = (domain = "http://localhost:8080/pc", order) => {
let cooks = "JSESSIONID=AFAFWEEVV2323GG";
fetch(deleteorder, {
method: `GET`,
credentials: 'same-origin',
headers: {
"Content-type": `application/x-www-form-urlencoded`,
},
})
.then(res => {
console.log(res.status);
})
.catch(error => {
console.log(error);
});
};
}
When 函数运行并返回 200
但数据保持不变,这意味着顺序保持不变。你们中的一个可以阐明一些吗?我正处于学习 fetch api 的初学者阶段,因此非常感谢任何反馈。
Fetch()
只是发送当前文档的 cookie,所以只需将 cookie 添加到 document.cookie
。
static deleteorder = (domain = "http://localhost:8080/pc", order) => {
document.cookie = "JSESSIONID=AFAFWEEVV2323GG";
fetch(deleteorder, {
method: `GET`,
credentials: 'same-origin',
})
.then(res => {
console.log(res.status);
})
.catch(error => {
console.log(error);
});
};