Skip to content

Instantly share code, notes, and snippets.

@bogdan-nourescu
Created February 25, 2019 19:28
Show Gist options
  • Save bogdan-nourescu/b7673535bfca8ffb45ee45057a9f2e97 to your computer and use it in GitHub Desktop.
Save bogdan-nourescu/b7673535bfca8ffb45ee45057a9f2e97 to your computer and use it in GitHub Desktop.
<html>
<head>
<style>
</style>
<script>
var persoane=[];
function ajax() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
persoane= JSON.parse(this.responseText);
console.log(persoane);
draw();
}
};
xhttp.open("GET", "https://test-d2273.firebaseio.com/.json", true);
xhttp.send();
}
function draw(){
/*
"..."+ variabila +"..."
""
''
`
...${variabila}...
`*/
var str = ``;
for(var i=0;i<persoane.length;i++){
str += `
<tr>
<td>${i+1}</td>
<td>${persoane[i].nume}</td>
<td>${persoane[i].prenume}</td>
<td>${persoane[i].varsta}</td>
</tr>
`
str += ""+
"<tr>"+
"<td>"+(i+1)+"</td>"+
"<td>"+persoane[i].nume+"</td>"+
"<td>"+persoane[i].prenume+"</td>"+
"<td>"+persoane[i].varsta+"</td>"+
"</tr>"
}
document.querySelector("table>tbody").innerHTML=str;
}
</script>
</head>
<body onload="ajax()">
<table border="1" >
<thead>
<tr>
<th onclick="sorteaza('nume');">Nume</th>
<th onclick="sorteaza('prenume');">Prenume</th>
<th onclick="sorteaza('varsta');">Varsta</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment