if (this.readyState == 4 && this.status == 200) {
the above condition is missing in the response, which leads to print the data twice.
var space = new XMLHttpRequest();
space.open("GET", "http://api.open-notify.org/astros.json", "jsonp");
space.send(null);
space.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var res = JSON.parse(space.response);
var totalPeople = res.number;
for (i = 0; i < totalPeople; i++) {
var pElement = document.getElementById("space_astronauts");
var firstChild = pElement.firstChild;
var astronautsElement = document.createElement("a");
var txt = document.createTextNode(res.people[i].name + " ");
astronautsElement.appendChild(txt);
pElement.insertBefore(astronautsElement, firstChild);
}
}
}