【问题标题】:Amp Html Form SubmitionAmp Html 表单提交
【发布时间】:2018-06-28 14:36:12
【问题描述】:

我是 amphtml 的新手。我想在 amp Html 中提交一个表单,在 localhost 中输入 type="file"。我该如何继续?当输入 type="text" 完美运行时。但是在输入中type="文件",会报错。

【问题讨论】:

    标签: html amp-html


    【解决方案1】:

    我假设您使用的是 method="GET",<input type="file" /> 不适用于 method="get",您必须使用 method="post" 和属性 action-xhr 来代替 action。

    For example you can check here

    JS 代码

    <script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
    

    HTML 代码:

     <form method="post"
      action-xhr="where-you-want-submit"
      target="_top">
      <p>Form Submission with Page Reload</p>
      <div class="ampstart-input inline-block relative mb3">
        <input type="file" name="any_name">
      </div>
      <input type="submit"
        value="Submit"
        class="ampstart-btn caps">
    </form>
    

    【讨论】:

    • 不,我使用表单方法作为 post.and 也使用 action-xhr。我注意到,当我使用文本输入类型时,后端代码返回标题作为 application/json。但是当我使用输入类型为文件,它以文本/html返回标题。
    猜你喜欢
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    相关资源
    最近更新 更多