1
when I type the console.log(Response) command it displays all the information in the browser console, but for some detail, I’m not able to display the data inside my div which is in the html snippet below. Can someone point out to me what I’m missing?
<script>
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp.responseText);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
myFunction(url);
function myFunction(response) {
var arr = JSON.parse(JSON.stringify(response));
var i;
var out = "<div>";
for(i = 0; i < arr.length; i++) {
out += "<a href='#' class='samba-playlist-trigger list-group-item active' data-mediaid=" + arr[i].id + "></a>";
}
out += "</div>";
document.getElementById("id01").innerHTML = out;
}
</script>
The display part in the html page
<div class="container">
<div class="row">
<div id="id01"></div>
</div>
</div>
What’s the idea of
myFunction(url);
? and where are you instantiating ajax? Something else, theJSON.stringify
doesn’t make sense because you’re getting a string.– Sergio