【发布时间】:2019-10-14 00:27:51
【问题描述】:
所以,我上周发布了 this issue 关于重复标题的帖子。我已经解决了这个问题,我确实相信,但现在它又出现了一个我似乎无法解决的新错误。我通过在表单提交函数的 PHP 中删除第二次添加的标题并只允许它们存在于 htaccess 中来解决我的上一个问题。
表单提交 PHP 中存在的唯一标题是将 Content-Type 设置为 application/json。
当我提交表单时,会弹出提交消息。然后,当表单提交/失败时,它不会传回 amp-mustache 模板标签中包含的消息。
<div submitting>
<template type="amp-mustache">
Form submitting... Thank you for waiting.
</template>
</div>
<div submit-success>
<template type="amp-mustache">
Thanks, your message has been sent successfully.
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Unfortunately your message could not be sent. Please try again later.
</template>
</div>
环顾四周后,似乎表明我的Content-Type 在提交表单的PHP 上未设置为application/json,但是当我检查Chrome 中的“网络”选项卡时,就标题而言,一切看起来都很好担心。
提交表单的 PHP (xhr-contact-test.php) 响应标头:
access-control-allow-credentials: true
access-control-allow-headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token
access-control-allow-methods: POST, GET, OPTIONS
access-control-allow-source-origin: https://www.craigattachments.com
access-control-expose-headers: AMP-Access-Control-Allow-Source-Origin
amp-access-control-allow-source-origin: https://www.craigattachments.com
cache-control: max-age=604800
cf-railgun: 4d68972973 0.01 0.656948 0030 cc99
cf-ray: 4de04cf54e22ccfe-EWR
content-encoding: br
content-security-policy: default-src * data: blob:; img-src * 'self' data: https: https://static.craigmanufacturing.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https://cdn.ampproject.org/v0.js https://cdn.ampproject.org/v0/ https://cdn.ampproject.org/viewer/ https://cdn.ampproject.org/v/ https://cdn.ampproject.org/rtv/ https://static.craigmanufacturing.com *.google.com https://maps.googleapis.com/maps/api/js/ https://maps.googleapis.com/maps/api/place/js/ https://cdn.polyfill.io https://cdnjs.cloudflare.com/ajax/; object-src 'self' https://www.craigattachments.com/pdf/; media-src 'self' https://www.craigattachments.com/pdf/; plugin-types application/pdf; style-src 'self' 'unsafe-inline' https://static.craigmanufacturing.com https://cdn.ampproject.org/rtv/ https://fonts.googleapis.com/; base-uri 'self';
content-type: application/json
date: Tue, 28 May 2019 12:41:04 GMT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expires: Tue, 04 Jun 2019 12:41:03 GMT
feature-policy: microphone 'none'; payment 'none'; geolocation *; sync-xhr 'self' https://www.craigattachments.com
referrer-policy: same-origin
server: cloudflare
status: 200
strict-transport-security: max-age=31536000
vary: User-Agent
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
它传回的错误如下并指向 amp-form.js 上的第 1073 行,这是在适当的 amp-mustache 模板标签上设置 i-amphtml-rendered 属性的函数。调查这导致我认为内容类型是导致问题的原因,但现在似乎设置正确并且错误仍然存在。
Uncaught (in promise) TypeError: b.setAttribute is not a function
我在此链接打开了我的测试联系表:https://www.craigattachments.com/contact-us-test/。
对我下一步应该去哪里有什么想法吗?我尝试了一些方法,例如测试某些标头是否存在,在我的 htaccess 中设置 Content-Type 以及仅在 PHP 中设置我的标头。
其他对此挂断的人的解决方案...如果您将电子邮件作为数组回显,例如echo json_encode(array($email));,则会出现此错误。无论如何,从等式中取出数组似乎对我来说是修复它 - echo json_encode($email);
2019/06/12 更新:非常感谢 Aaron。如果将来有人遇到此问题,则已为该问题提供了一些更好的错误处理参数:https://github.com/ampproject/amphtml/pull/22576
【问题讨论】: