我刚开始使用AMP动态电子邮件框架,开始使用它时遇到了一些麻烦。具体来说,我的问题是,当在电子邮件客户端上提交表单时(我使用gmail),它将重新加载整个客户端,而不是简单地通过XMLHttpRequest(XHR)接收响应。到目前为止,这是我的HTML,几乎可以直接从示例here中复制。
<!doctype html>
<html ⚡4email>
<head>
<meta charset="utf-8">
<title>amp-form</title>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- ## Setup -->
<!--
Import the library.
-->
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
<link rel="canonical" href="https://ampbyexample.com/components/amp-form/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<!--
Customize success or error messages by using `amp-form-submit-success` and `amp-form-submit-error` classes.
-->
<style amp-custom>
form.amp-form-submit-success [submit-success],
form.amp-form-submit-error [submit-error]{
margin-top: 16px;
}
form.amp-form-submit-success [submit-success] {
color: green;
}
form.amp-form-submit-error [submit-error] {
color: red;
}
form.amp-form-submit-success.hide-inputs > input {
display: none;
}
</style>
</head>
<body>
<!-- Use `as-you-go` strategy to show validation messages as the user is interacting with the form. -->
<form method="post"
class="p2"
action-xhr="MY_API_ENDPOINT"
target="_top"
custom-validation-reporting="as-you-go">
<p>Form Custom Validation: <code>as-you-go</code></p>
<div class="ampstart-input inline-block relative m0 p0 mb3">
<input type="text" class="block border-none p0 m0" id="as-you-go-name" name="name" placeholder="Name..." required pattern="\w+\s\w+">
<span visible-when-invalid="valueMissing"
validation-for="as-you-go-name"></span>
<span visible-when-invalid="patternMismatch"
validation-for="as-you-go-name">
Please enter your first and last name separated by a space (e.g. Jane Miller)
</span>
<input type="email" class="block border-none p0 m0" id="as-you-go-email" name="email" placeholder="Email..." required>
<span visible-when-invalid="valueMissing"
validation-for="as-you-go-email"></span>
<span visible-when-invalid="typeMismatch"
validation-for="as-you-go-email"></span>
</div>
<input type="submit" value="Subscribe" class="ampstart-btn caps">
<div submit-success>
<template type="amp-mustache">
Success! Thanks {{name}} for trying the <code>amp-form</code> demo! Try to insert the word "error" as a name input in the form to see how <code>amp-form</code> handles errors.
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Error! Thanks {{name}} for trying the <code>amp-form</code> demo with an error response.
</template>
</div>
</form>
请帮助!我正在使用NodeMailer通过带有NodeJS的STMP发送电子邮件。
谢谢!