Skip to content

[html] 第448天 如何通过表单下载文件? #2608

Open
@haizhilin2013

Description

@haizhilin2013

第448天 如何通过表单下载文件?

3+1官网

我也要出题

Activity

echo-LJ

echo-LJ commented on Jul 7, 2020

@echo-LJ
  1. form 表单的action设置为接口地址,设置method为post/get
    post方法
    根据需要传递的参数设置多个input:name=key, value=value
    如果请求的接口不需要参数,建议设置一个input,否则可能会引起报错。
  2. submit提交到后台
shuai4983958

shuai4983958 commented on Jul 8, 2020

@shuai4983958

const from =document.createElement('form');
form.setAttribute('method','get');
form.setAttribute('action',url); // 下载文件的url
form.submit()

montilloo

montilloo commented on Sep 23, 2020

@montilloo

const from =document.createElement('form');
form.setAttribute('method','get');
form.setAttribute('action',url); // 下载文件的url
form.submit()

需要在提交之前把form表单添加到document,否则会报Form submission canceled because the form is not connected.警示。使用的浏览器Microsoft Edge 版本 85.0.564.51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@shuai4983958@montilloo@echo-LJ

        Issue actions

          [html] 第448天 如何通过表单下载文件? · Issue #2608 · haizlin/fe-interview