amp-mustache成功/错误消息不显示

时间:2019-05-28 12:57:30

标签: php .htaccess amp-html

因此,我上周发布了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属性。对此进行调查后,我开始认为内容类型是导致此问题的原因,但现在似乎已正确设置并且错误仍然存​​在。

  

未捕获(承诺)TypeError:b.setAttribute不是函数

我已经通过以下链接打开了我的测试联系表:https://www.craigattachments.com/contact-us-test/

我对接下来应该去哪里有任何想法?我已经尝试了一些方法,例如测试某些标头的存在,在htaccess中设置Content-Type以及仅在PHP中设置标头。

1 个答案:

答案 0 :(得分:1)

我快速浏览了一下,看起来renderTemplate方法返回的对象是一个数组,而不是元素。

enter image description here

https://github.com/ampproject/amphtml/blob/master/extensions/amp-form/0.1/amp-form.js#L1121

可能代码中有错误。检查div,看起来它们也是相同的成功消息。是否可以重现,这是一个非常简单的形式演示,仅需复制的最低限度。例如只是形式 谢谢