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

121
Visualizações
UI is not updating on click event that triggers a fetch on Firefox Developer

I built a project of Frontend Mentors called Advice generator App using HTML, CSS & JS. There is a bug with my solution and Firefox Developer. When I clicked on the button, the event listener run the fetch function and makes a request and changes the UI accordingly to the data received from the response; the problem is that when I click again, the UI doesn't change and the console shows the same response as before; this didn't happen on brave browser and I suppose other Chromium-based browsers as well, I want to know why this happens with Firefox Developer?

  • Link of repo: https://github.com/Perlishnov/advice-generator-app-main

  • Link of website: https://advice-generator-app-main-kappa.vercel.app/

"use strict";

//Html Elements
const rollDice = document.getElementById("roll-dice");
const adviceNumber = document.getElementById("advice-number");
const adviceParagraph = document.getElementById("advice");
const url = "https://api.adviceslip.com/advice";

//Dice button logic
rollDice.addEventListener("click", () => {
  fetch(url)
    .then((response) => response.json())
    .then(
      (data) => (
        (adviceNumber.textContent = data.slip.id),
        (adviceParagraph.textContent = data.slip.advice)
      )
    );
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's looks like a cache memory issue. if the url is the same, the browser uses what is already in the cache.

The simplest way to fix that: add a counter on your url, to force the cache

"use strict";

//Html Elements
const
  rollDice        = document.getElementById('roll-dice')
, adviceNumber    = document.getElementById('advice-number')
, adviceParagraph = document.getElementById('advice')
, url = 
   { ref   : 'https://api.adviceslip.com/advice'
   , count : 0
   }
 ;

//Dice button logic
rollDice.onclick = () => 
  {
  fetch( `${url.ref}?c=${++url.count}`)
  .then( r => r.json() )
  .then( data =>
    {
    adviceNumber.textContent    = data.slip.id
    adviceParagraph.textContent = data.slip.advice
    })
  }
<div>
  <h3 id="advice-number"> n </h3>
  <p  id="advice">...</p>
</div>
<button id="roll-dice"> roll-dice </button>
  

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