0

I'm consuming a JSON API with JavaScript and adding that content in HTML with append but when you go to another page and click Back in the browser the content is reloaded so I want to know a way to avoid this, this is the JavaScript code I'm Using.

var request = new XMLHttpRequest();
request.open('GET', 'https://localhost:3000/api', true);
request.onload = function () {
  var data = JSON.parse(this.response);
  if (request.status >= 200 && request.status < 400) {
    data.forEach(v => {
      const card = '<span><div class="card">v.content</div></span>';
      $("#data").append(card);
    });
  }else{
    console.log('Error al cargar el contenido');
  }
}
request.send();

thanks for your help

1 Answers1

0

You would have to save the response from the get request locally and load from that.

Checkout this answer to a similar question https://stackoverflow.com/a/17104536/10997917

andrewjazbec
  • 859
  • 8
  • 20