【发布时间】: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);
});
};
【问题讨论】:
-
你解决了吗?我遇到了同样的问题。