1

Hi guys I'm learning how to use AMP and coming to an issue where my api requests are coming back with an empty body. My get route works fine and my post route works for non-AMP form submissions.

If someone could let me know what Im doing wrong it'd be appreciated!

HTML for the AMP form, from the amp website & contains no amp errors on load.

<form method="post" action-xhr="/subscribe" target="_top" style="width: 75%; margin: auto;">
            <fieldset>
                <label>
                    <span>Name:</span>
                    <input type="text" name="name" required>
                </label>
                <br>
                <label>
                    <span>Email:</span>
                    <input type="email" name="email" required>
                </label>
                <br>
                <input type="submit" value="Subscribe">
            </fieldset>
            <div submit-success>
                <template type="amp-mustache">
                    Subscription successful!
                </template>
            </div>
            <div submit-error>
                <template type="amp-mustache">
                    Subscription failed!
                </template>
            </div>
        </form>

API routes, get works fine and the post works for non-AMP forms

module.exports = function (app) {
    // Subs get
    app.get("/api/all", function (req, res) {
        Sub.findAll({}).then(function (results) {
            res.json(results);
        });

    });

    // Subs post
    app.post("/subscribe", function (req, res) {
        console.log("Sub Data:");
        console.log(req.body);        
    });
};

1 Answers1

1

The first and the foremost thing to work for AMP form is to use the following script

<script async="" custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>

Secondly your action-xhr must be full domain path and must be HTTPS

From this

action-xhr="/subscribe"

To this

action-xhr="https://yourdomain.com/subscribe"
Channaveer Hakari
  • 2,769
  • 3
  • 34
  • 45
  • Hello Channaveer, how you going? I am trying to use a repository created by you to make unique slugs, could you take a look in that quesiton? please? https://stackoverflow.com/questions/70906354/unique-profile-slug-with-php-and-pdo – Sophie Jan 29 '22 at 17:41
  • @Sophie Thank you for taking your time and getting in touch with me for the solution. I have given my best, to answer your question. Kindly take a look. – Channaveer Hakari Jan 31 '22 at 05:46
  • HI thank you soo much for your time, the guys there got mad I dont know why... – Sophie Jan 31 '22 at 10:07
  • @Sophie No worries. Good to know that it worked for you. Yup, he was acting kinda weird even after telling him that I am just giving different suggestions. – Channaveer Hakari Jan 31 '22 at 10:23
  • I dont know if they know the real importance of slugs for SEO – Sophie Jan 31 '22 at 10:25
  • I work with SEO, and rank for words with millions searchs, and I just want to implement a slug for the users of my system, to rank their names in google search... well, thats not toohard to understand, but I dont think he will understand – Sophie Jan 31 '22 at 10:28