Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
htmx.ajax only called twice when making multiple queries

I am using Alpinejs' $watch() on a given property inside multiple x-data blocks to call htmx.ajax with a custom handler whenever that property changes. Here is a snippet:

HTML:

<div x-data="{profiles:[]}">
  <div x-data="..." x-init="$watch('profiles', val=>onProfilesChanged())">...</div>

  <div x-data="..." x-init="$watch('profiles', val=>onProfilesChanged())">...</div>

  <div x-data="..." x-init="$watch('profiles', val=>onProfilesChanged())">...</div>

  <div>
  <!-- profiles modified here in response to user input -->
  ...
  </div>
</div>

Javascript:

function onProfilesChanged() {
  htmx.ajax('GET', ..., {'handler': (evt,response)=>{...}});
}

Debugging in the browser I can see onProfilesChanged being called as expected (3 times), but only 2 network requests are sent and the callback handler is then only executed twice . The requests seem to correspond to the first and last call, and everything in-between is somehow lost (tried with more $watch() callbacks). The behavior is the same on both Firefox and Chromium so I doubt it is a browser limitation, but I couldn't find anything in the htmx documentation concerning the maximum number of Ajax requests that can be queued.

I am at a total loss here, any insight into what might be going on would be greatly appreciated. Thanks!

Edit: the problem also happens when using htmx.ajax() inside a for loop, so this really does seem to be on the htmx side. There is an hx-sync tag to set the queue behavior for hx-get/post.. tags, but doesn't seem to work with the JS API.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Finally managed to find a workaround: adding a dynamic source element to the Ajax request's options attributes fixes the issue. I am still having a limit of 2 requests per element in the case of for loops, but requests from different sources have different queues now.

Keeping this for future reference in case it helps someone else.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda