如何关闭http请求中的会话
How to close the session in http request
我试图在发出请求后立即结束会话,但会话保持打开状态,因为当我在新选项卡上打开 URL 时,它已与我发出请求的用户一起登录,并且即使我用不同的用户登录,在发出 http 请求后,用户也会更改为 http 请求中的用户。我想要的是一旦发出请求并重置表单,会话就应该关闭。
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4 && this.status === 201) {
//xhr.abort(); not working
//xhr.open("POST", "URL");
//xhr.setRequestHeader("authorization", "Basic aaaaa"); not working
form.reset();
}
if (this.status === 404) {
form.reset();
}
});
xhr.open("POST", "URL");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "Basic something");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
使用xhr.abort 也不起作用。任何想法如何在请求后关闭会话
问题可能是您应用了 async
选项。该选项已被弃用。我做过的研究表明 .abort();
应该有效。
第一个:
xhr.open("POST", "URL",true);
进入:
xhr.open("POST", "URL");
然后,它应该工作:
xhr.abort();
http://help.dottoro.com/ljomfaxv.php
或者您可以尝试使 xhr 变量为空。
xhr = null;
xhr.withCredentials = true;
删除后一切正常。
我试图在发出请求后立即结束会话,但会话保持打开状态,因为当我在新选项卡上打开 URL 时,它已与我发出请求的用户一起登录,并且即使我用不同的用户登录,在发出 http 请求后,用户也会更改为 http 请求中的用户。我想要的是一旦发出请求并重置表单,会话就应该关闭。
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4 && this.status === 201) {
//xhr.abort(); not working
//xhr.open("POST", "URL");
//xhr.setRequestHeader("authorization", "Basic aaaaa"); not working
form.reset();
}
if (this.status === 404) {
form.reset();
}
});
xhr.open("POST", "URL");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "Basic something");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
使用xhr.abort 也不起作用。任何想法如何在请求后关闭会话
问题可能是您应用了 async
选项。该选项已被弃用。我做过的研究表明 .abort();
应该有效。
第一个:
xhr.open("POST", "URL",true);
进入:
xhr.open("POST", "URL");
然后,它应该工作:
xhr.abort();
http://help.dottoro.com/ljomfaxv.php
或者您可以尝试使 xhr 变量为空。
xhr = null;
xhr.withCredentials = true;
删除后一切正常。