首页 > 解决方案 > Fetch() - 如何使用重定向显示位置页面:follow

问题描述

问题是:

  1. 我用 POST 发送了 Fetch(),这是一个登录表单,
        fetch('/login', {
            method: 'POST',
            body: _formData,
            credentials: 'same-origin',
            redirect: 'follow'
        }).then((response) => {
            if (response.redirected) {
                 // window.location.href = response.headers.get('Location');
            }
        }).catch(function (err) {
            console.info('fetch() login issue: ' + err);
        });
  1. 然后,服务器端响应重定向:
HTTP/1.1 302 Found
Server: nginx/1.16.1
Date: Fri, 18 Sep 2020 09:33:33 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 10
Connection: keep-alive
Set-Cookie: _token=1050; Secure; HttpOnly
Location: /main/top
  1. 而我所看到的 - 浏览器使用 GET 请求重定向页面(这里是/main/top),并根据需要获取完整内容 HTML,我看到 Fiddler 的流量,
  2. 但这很奇怪,-浏览器获取内容,但不显示重定向页面!
  3. catch之后没有错误fetch

这能是什么??

标签: javascripthtmlredirectbrowserfetch

解决方案


推荐阅读