我正在使用AMP表单发送数据到我的Golang服务器。即使我跳过了发送数据的所有处理,只写了代码200的响应,就像AMP表单引用中所说的那样,我仍然会得到提交错误模板。
这是我的表单(我跳过了字段,因为它太长了)
<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>这是服务器响应的一个例子:
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问题可能在服务器端吗?我搞不懂..。任何想法都是非常感谢的。
发布于 2018-09-26 21:43:10
我觉得很尴尬。经过几天的思考和回到这个问题,当我终于决定发布一个问题时,我想到了一个想法,就在我做完之后.
问题在于头Content-type。它必须设置为JSON:
Content-type: application/json发布于 2019-05-28 09:42:42
确保您实现了AMP CORS头。
如果请求来自您自己(您的域而不是安培缓存服务器),那么您可以设置以下标头-
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'
});https://stackoverflow.com/questions/52526339
复制相似问题