I'm trying to fill a list of characters from an Api, but I have a question about how to fill the array, I had difficulties just having 10 characters and that these are listed and generate a link to a movie . So far I have the API call, but I only print the Json in the console, having created a connection with the html
function ajax_get(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200) {
console.log('responseText:' + xmlhttp.responseText);
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {
console.log(err.message + " in " + xmlhttp.responseText);
return;
}
callback(data);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
ajax_get("https://swapi.co/api/people/", function(data) {
var html = "<h2>" + data["title"] + "</h2>";
html += "<h3>" + data["description"] + "</h3>";
html += "<ul>";
for (var i=0; i < "https://swapi.co/api/people/10"; i++) {
html += '<li><a href="' + data["people"][i]["name"] + '">' + data["people"][i]["mass"] + "</a></li>";
}
html += "</ul>";
document.getElementById("text").innerHTML = html;
});
I appreciate the attention