This is an AMP html site. I have forms working find on another domain but this is giving unexpected JSON.parse error:
Failed to parse response JSON: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
What JSON data? I don't get it. Might that be set somewhere outside the code I'm writing, like in php.ini, .htaccess or some server file?
I'm befuddled because I have it working just fine on another domain.
<!DOCTYPE html><html amp>
...
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
...
<body>
<form class="sample-form"
method="post"
action-xhr="https://www.example.com/amp_TEST.php"
target="_top">
<input type="text" id="theid" name="name" placeholder="Name..." value="my name here" required>
<input type="submit" value="Submit">
</form>
And, the receiving file, amp_TEST.php
if(!empty($_POST)){
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: Content-Type");
header("Access-Control-Allow-Origin: https://www-example-com.cdn.ampproject.org");
header("Access-Control-Allow-Source-Origin: https://www.example.com");
header("AMP-Access-Control-Allow-Source-Origin: https://www.example.com");
header("AMP-Access-Control-Allow-Methods: *");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header('Access-Control-Allow-Headers', 'Content-Type');
}
echo '<pre>POST: ' . print_r($_POST, true) . '</pre>';