Skip to content

Should htmx:configRequest event handlers complete before ajax call is sent? #1599

Answered by Telroshan
bjd183 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, events do not run asynchronously.
You can observe that in this JSFiddle, where the htmx:configRequest handler waits for 3 seconds before releasing. The request isn't sent before that handler exits.

What is probably asynchronous in your scenario though, is that separate request you're making to get a token.
htmx doesn't support async listeners, so something like this JSFiddle won't work, and the request will be sent, ignoring the await

I guess that what you could do here is, simply don't use htmx:configRequest, rather bind your own JS listener that fetches the token then calls htmx.ajax to make the htmx request
Something like this, that you can play it on this JSFiddle

<button id="button

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bjd183
Comment options

Answer selected by bjd183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants