首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >放大器表单总是显示提交错误,即使在响应代码200上也是如此。

放大器表单总是显示提交错误,即使在响应代码200上也是如此。
EN

Stack Overflow用户
提问于 2018-09-26 21:36:50
回答 2查看 1K关注 0票数 1

我正在使用AMP表单发送数据到我的Golang服务器。即使我跳过了发送数据的所有处理,只写了代码200的响应,就像AMP表单引用中所说的那样,我仍然会得到提交错误模板。

这是我的表单(我跳过了字段,因为它太长了)

代码语言:javascript
复制
<form action-xhr="/contactus" method="POST" class="contactForm" target="_top" custom-validation-reporting="show-all-on-submit" id="contactForm">
    <fieldset>
        <!-- divs with input and submit button -->
    </fieldset>
    <div submit-success>
        <template type="amp-mustache">
            Success! 
        </template>
    </div>
    <div submit-error>
        <template type="amp-mustache">
            Error! 
        </template>
    </div>
</form>

这是服务器响应的一个例子:

代码语言:javascript
复制
HTTP/1.1 200 OK
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Sun, 23 Sep 2018 21:48:15 GMT
Content-Length: 23
Content-Type: application/x-gzip

问题可能在服务器端吗?我搞不懂..。任何想法都是非常感谢的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-26 21:43:10

我觉得很尴尬。经过几天的思考和回到这个问题,当我终于决定发布一个问题时,我想到了一个想法,就在我做完之后.

问题在于头Content-type。它必须设置为JSON:

代码语言:javascript
复制
Content-type: application/json
票数 0
EN

Stack Overflow用户

发布于 2019-05-28 09:42:42

确保您实现了AMP CORS头。

参考:https://amp.dev/documentation/guides-and-tutorials/learn/amp-caches-and-cors/amp-cors-requests?referrer=ampproject.org

如果请求来自您自己(您的域而不是安培缓存服务器),那么您可以设置以下标头-

代码语言:javascript
复制
if (req.headers['amp-same-origin'] === 'true') {
    origin = req.query.__amp_source_origin;
    sourceOrigin = origin;
}

res.set({
    'Access-Control-Allow-Origin': origin,
    'AMP-Access-Control-Allow-Source-Origin': sourceOrigin,
    'Access-Control-Allow-Source-Origin': 'AMP-Access-Control-Allow-Source-Origin',
    'Access-Control-Expose-Headers': 'Access-Control-Allow-Origin' + ', AMP-Access-Control-Allow-Source-Origin' + ', Access-Control-Allow-Source-Origin'
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52526339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档