作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 fetch() 函数之后将用户重定向到新网页。我使用 Facebook 登录按钮,当用户通过身份验证时,我想将他重定向到包含他的数据的新页面。所以我想知道最好的方法是什么。
我认为 window.location + session 变量可以工作,但我很确定有比此方法更正确的方法,例如 then() 函数之后的重定向函数。
我厌倦了使用 fetch().then().redirect() 但它不起作用,我想做的是像 ...().redirect(function(userDatas, url){.. .});
//this is inside the facebook connection function
fetch('/connect',options).then(function(response){
response.json().then(function(value){
window.location = 'http://localhost:3000/fight.html';
console.log(value);
});
//after this function, I would like to go to this fight.html page
所以我希望用户在FB连接后到达fight.html页面及其数据。
最佳答案
你的做法是错误的。您正在对 response.json()
的响应调用 .then() 而不是主 promise 链。尝试:
fetch('/connect',options)
.then(function(response) {
return response.json();
})
.then(function(value) {
window.location = 'http://localhost:3000/fight.html';
console.log(value);
});
关于javascript - 如何在 fetch() 函数之后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58595026/
我是一名优秀的程序员,十分优秀!