Search code examples
goamp-html

AMP Form always showing submit-error, even on response code 200


I am using AMP form to send data to my Golang server. Even if I skip all handling of data sent and just write response with the code 200 as is said in AMP form reference, I still get shown the submit-error template.

This is my form (I skipped the fields because it would be too long)

<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>

And this is an example of server response:

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

Could the problem be on server side? I can't figure it out... Any idea is much appreciated


Solution

  • I feel embarrassed. After a couple of days wondering and getting back to this issue, when I finally decide to post a question, an idea struck me right after I do it...

    The problem is with header Content-type. It must be set to JSON:

    Content-type: application/json