SeasonalShot SeasonalShot - 5 months ago 8
jQuery Question

Javascript doesn't update document in browser

I have a data.json in my server directory. I am using the following code from w3school to show the data in the browser. W3school Snippet Link

<button type="button" onclick="loadDoc()">Change Content</button>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;

}
};
xhttp.open("GET", "/static/data.json", true);
xhttp.send();
}
</script>
</html>


When i click the button, I am able to see the data.json in my webpage. But when i change the data.json and click the button again (without refreshing the page), the updated data isn't shown in the browser.

Am i missing something here?

Answer
   xhttp.open("GET", "/static/data.json?something=RANDOMGUID", true);