Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I send a POST/GET Request on an HTML tag in Pug?

I want to send a GET request on an anchor tag in pug. Is it possible without using form & submit button?

I did this code but it is not executing the server side route, it is directly displaying the page.

nav
    ul.pagination
        li.page-item
            a.page-link Prev
        each pageNumber in pages
            li.page-item
                a.page-link(href="/admin?page="+pageNumber)=pageNumber
        li.page-item
            a.page-link Next

I want to do something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a.page-link(method="GET" action="/admin?page="+pageNumber)=pageNumber

>Solution :

Pug just generates HTML. So start by forgetting about Pug and focus on the HTML you want to generate.

Links make GET requests. They can’t do anything other than make a GET request. They don’t accept an method attribute.

The URL to make the GET request to is specified by the href attribute, not an action attribute.

a.page-link(href="/admin?page="+pageNumber)=pageNumber already makes the request you appear to want.

It must be executing some route on the server, otherwise the server wouldn’t respond with a page for the browser to render.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading