Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda