Amp html amp表格验证不存在';即使使用官方文档代码,也无法工作

Amp html amp表格验证不存在';即使使用官方文档代码,也无法工作,amp-html,amp-form,Amp Html,Amp Form,我试图在amp表单组件上实现自定义字段验证,但我所有的努力都是徒劳的 尽管XHR请求返回有效的JSON,但它不会使字段无效,并且不会显示错误消息 我尝试了官方文档中的代码:没有运气 转到Git代码示例:仍然没有 有人能告诉我我做错了什么吗 以下是完整的代码: 以下是我的脚本附件: <script async src="https://cdn.ampproject.org/v0.js"></script> <script async custom-

我试图在
amp表单
组件上实现自定义字段验证,但我所有的努力都是徒劳的

尽管
XHR请求返回有效的JSON
,但它不会使字段无效,并且不会显示错误消息

我尝试了官方文档中的代码:没有运气

转到Git代码示例:仍然没有

有人能告诉我我做错了什么吗

以下是完整的代码:

以下是我的脚本附件:

<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
<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-latest.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>

完整的代码可以在

中找到,解决方案很简单!响应头的状态为200

显然,脚本在检查JSON本身之前先检查请求的状态

以下是PHP中的验证端点,供将来参考:

<?php

    header('HTTP/1.1 400 Bad Request');
    header('Content-Type: application/json');
    header('Access-Control-Allow-Methods: POST');
    header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]. '');
    header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
    header('AMP-Access-Control-Allow-Source-Origin: '.$_GET["__amp_source_origin"].'');
    header('Access-Control-Allow-Credentials: true');

    $response = array(
        "verifyErrors" => array(
            array(
                "name" => "email",
                "message" => "That email is already taken."
            ),
            array(
                "name" => "zip",
                "message" => "The city and zip do not match."
            )
        )
    );

    echo json_encode($response);

?>

{
    "verifyErrors": [
        {
            "name": "email",
            "message": "That email is already taken."
        },
        {
            "name": "zip",
            "message": "The city and zip do not match."
        }
    ]
}
<?php

    header('HTTP/1.1 400 Bad Request');
    header('Content-Type: application/json');
    header('Access-Control-Allow-Methods: POST');
    header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]. '');
    header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
    header('AMP-Access-Control-Allow-Source-Origin: '.$_GET["__amp_source_origin"].'');
    header('Access-Control-Allow-Credentials: true');

    $response = array(
        "verifyErrors" => array(
            array(
                "name" => "email",
                "message" => "That email is already taken."
            ),
            array(
                "name" => "zip",
                "message" => "The city and zip do not match."
            )
        )
    );

    echo json_encode($response);

?>