【问题标题】:No body on AMP form submitAMP 表单上没有正文提交
【发布时间】:2020-07-22 16:53:38
【问题描述】:

大家好,我正在学习如何使用 AMP,但遇到了一个问题,即我的 api 请求返回一个空的正文。我的 get 路由运行良好,我的 post 路由适用于非 AMP 表单提交。

如果有人可以让我知道我做错了什么,将不胜感激!

AMP 表单的 HTML,来自 amp 网站,加载时不包含任何 amp 错误。

<form method="post" action-xhr="/subscribe" target="_top" style="width: 75%; margin: auto;">
            <fieldset>
                <label>
                    <span>Name:</span>
                    <input type="text" name="name" required>
                </label>
                <br>
                <label>
                    <span>Email:</span>
                    <input type="email" name="email" required>
                </label>
                <br>
                <input type="submit" value="Subscribe">
            </fieldset>
            <div submit-success>
                <template type="amp-mustache">
                    Subscription successful!
                </template>
            </div>
            <div submit-error>
                <template type="amp-mustache">
                    Subscription failed!
                </template>
            </div>
        </form>

API 路由,获取工作正常,帖子适用于非 AMP 表单

module.exports = function (app) {
    // Subs get
    app.get("/api/all", function (req, res) {
        Sub.findAll({}).then(function (results) {
            res.json(results);
        });

    });

    // Subs post
    app.post("/subscribe", function (req, res) {
        console.log("Sub Data:");
        console.log(req.body);        
    });
};

【问题讨论】:

  • 你解决了吗?我遇到了同样的问题。

标签: forms amp-html


【解决方案1】:

使用 AMP 表单的首要任务是使用以下脚本

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

其次,您的 action-xhr 必须是完整的域路径,并且必须是 HTTPS

从这里

action-xhr="/subscribe"

到这里

action-xhr="https://yourdomain.com/subscribe"

【讨论】:

  • 你好 Channaveer,你好吗?我正在尝试使用您创建的存储库来制作独特的蛞蝓,您能看看那个问题吗?请? stackoverflow.com/questions/70906354/…
  • @Sophie 感谢您抽出宝贵时间与我联系以寻求解决方案。我已尽力回答您的问题。请看一看。
  • 嗨,非常感谢您抽出宝贵的时间,那里的人生气了,我不知道为什么...
  • @Sophie 不用担心。很高兴知道它对你有用。是的,即使在告诉他我只是给出不同的建议之后,他还是表现得有点奇怪。
  • 我不知道他们是否知道蛞蝓对于 SEO 的真正重要性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-21
相关资源
最近更新 更多