I'm trying to read all information from the JSON string. I'm also trying to read it with the help of AJAX. The purpose is to fill an innerHTML
with the information, but nothing works.
What is wrong with the code and how can it be solved?
function getResults() {
var obj = [
{ "number": "Bob", "position": "forward", "shoots": "left" },
{ "number": "John", "position": "forward", "shoots": "right" }
];
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var return_data = request.responseText;
document.getElementById("sportresults").innerHTML = return_data;
}
};
xhttp.open("GET", obj, true);
xhttp.send();
}