The basics: hx-post episode artwork

EPISODE · Jan 17, 2024 · 8 MIN

The basics: hx-post

from hx-pod · host Lazarus

Want to use POST requests in ajax, and submit forms from anywhere on the page?As promised in the episode, here are three ways to set up your CSRF token headers:1. Like normal in your forms:<input type="hidden" name="_token" value=""/> (the regular html way works with htmx, of course)2. Javascript<script>document.body.addEventListener('htmx:configRequest', (e) => {    e.detail.headers['X-CSRFToken'] = '';})</script>(add this to the bottom of your </body> so that EVERY request gets the right headers. I love this one!)hx-headers<div hx-post="/your-endpoint" hx-headers='{"X-CSRF-Token": "YourCSRFTokenHere"}'> <!-- Your content --> </div>(add this attribute along with your hx-post)

Episode metadata supplied by the publisher feed · Published Jan 17, 2024

Embed this episode

NOW PLAYING

The basics: hx-post

0:00 8:21

No transcript for this episode yet

We transcribe on demand. Request one and we'll notify you when it's ready — usually under 10 minutes.

No similar episodes found.

No similar podcasts found.

Frequently Asked Questions

How long is this episode of hx-pod?

This episode is 8 minutes long.

When was this hx-pod episode published?

This episode was published on January 17, 2024.

Is there a transcript available for this episode?

Yes, a full transcript is available for this episode. You can read the complete transcript on the episode page.

Can I download this hx-pod episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.
URL copied to clipboard!