This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

Fetch a JSON file with XMLHttpRequest

Content written as an JSON array will be converted into a JavaScript array.

const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {

// JSON array
  const myArr = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myArr[0];
}

// define XMLHttpRequest Object
xmlhttp.open("GET", "json_demo_array.txt", true);
xmlhttp.send();