Cache problem with ajax (text files) [duplicate]

1

I made the ajax connection to insert a .txt file into a div, but I modified the text and saved it but the text does not change (as if I had not saved it)

If you want to see the site that is the text (biology-> Food Chain): link

The "f12" of the page: link What is saved (left) and what appears (right): link

<script>
function corpo(titulo, texto) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("titulo").innerHTML = titulo;
        document.getElementById("corpo").innerHTML =
        this.responseText;
    }
  };
  xhttp.open("GET", texto, true);
  xhttp.send();
}

    
asked by anonymous 20.11.2018 / 12:44

1 answer

2

This is cache. Please try the following.

On the line.

xhttp.open("GET", texto, true);

Switch By:

xhttp.open("GET", texto + '?_now_=' + ((new Date()).getTime()), true);

Adding the current time in the request causes the entire request to be a new one to the browser, and then the cache is ignored.

    
20.11.2018 / 14:56