【发布时间】:2019-06-22 04:08:57
【问题描述】:
我正在为一个使用 fetch() api 向 node.js 服务器发送 POST 请求的 web 应用程序编写代码。在成功的请求服务器以重定向响应时,在 fetch() api 响应正文中接收到此重定向 url。在此之后,我应该怎么做才能将用户从 fetch 函数重定向到这个 URL。
fetch("/events/registration", {
method: "POST",
redirect:"follow",
headers: {
"Accept": "application/json , text/plain ,*/*",
"Content-type": "application/json"
},
body: JSON.stringify({
name,
email,
})
})
.then((res)=>res.json())
.then((data)=>{console.log(data);if(data.err)alert(data.err);Response.redirect()});
作为响应,我在 fetch api 中收到 redirect:true , url: "LinkOfRedirection/redirect",现在我应该怎么做才能将用户从这里重定向到 LinkOfRedirection/redirect。
【问题讨论】:
标签: javascript node.js redirect fetch