1

We have a basic form that we are trying to post to a MySQL database. Outside of AMP, it works.

When we submit the form with AMP, it returns the error: "Failed to parse response JSON:: Unexpected token".

Even when we remove the PHP from the handler script completely, it returns the same error.

We went right back to basics and just copied the example at https://ampbyexample.com/components/amp-form/ and changed only the line <form method="POST" action-xhr="/components/amp-form/submit-form" target="_top"> to point to action-xhr="https://ourdomain.com/form-handler.php".

So even with no PHP and this exact copy of the AMP by Example form, it returns the failed to parse response JSON error.

We have tried various bits of PHP to receive the JSON data but it doesn't just returns an error. We haven't been able to find any tutorials on how to write a compliant PHP handler script.

After many hours of Google, we've added these lines to our .htaccess:

Header set Access-Control-Allow-Origin "*"
Header set AMP-Access-Control-Allow-Source-Origin "https://ourdomain.com"

This has not helped unfortunately.

We haven't been able to find any other tutorials other than the AMP by Example page which only shows part of the process and not the handler script.

Thanks

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

0 Answers0