How do I get the result of a json and play straight into a table from my td? Is the form of getJSON right?
<script type = "text/javascript" language = "javascript">
$(document).ready(function(){
$.getJSON('../js/gcs.json', function(data) {
$('#inprog').append(data.inprog);
$('#queued').append(data.queued);
$('#total').append(data.total);
$('#resolved').append(data.resolved);
});
});
</script>
My json is this:
{
"inprog" : "123",
"queued" : "00",
"total" : "103",
"resolved" : "101",
"20days" : "0",
"8to20days" : "16",
"5to7days" : "17",
"1to4days" : "70",
"csatess" : "80%",
"csatcps" : "80%",
"csatgcs" : "100%",
"escalations" : "10"
}
My HTML:
<table class="hovertable" border="1">
<tr>
<thead>
<th colspan="6">DASHBOARD</th>
</thead>
</tr>
<tbody>
<tr>
<td><b>INPROG > 50</b></td>
<td id="inprog"></td>
<td><b>> 20 days</b></td>
<td>0</td>
<td><b>CSAT ESS</b></td>
<td>80%</td>
</tr>
<tr>
<td><b>QUEUED = 00</b></td>
<td>0</td>
<td><b>8 to 20 days</b></td>
<td>16</td>
<td><b>CSAT CPS</b></td>
<td>80%</td>
</tr>
<tr>
<td><b>TOTAL < 50</b></td>
<td>103</td>
<td><b>5 to 7 days</b></td>
<td>17</td>
<td><b>CSAT GCS</b></td>
<td>100%</td>
</tr>
<tr>
<td><b>RESOLVED >70</b></td>
<td>101</td>
<td><b>1 to 4 days</b></td>
<td>70</td>
<td><b>ESCALATIONS</b></td>
<td>10</td>
</tr>
</tbody>
</table>
UPDATE:
My whole code is like this, but I have not yet succeeded.
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scripttype="text/javascript" language = "javascript">
$(document).ready(function(){
$.getJSON('../js/gcs.json', function(data) {
var table = document.querySelector(".table tbody tr")
//pegando a tabela
//inserindo dinamicamente o objeto dentro da tabela
for(t in data){
//t posicao do objeto retorna 'inprog'
//objeto[t] retornaria '123'
$(table).append("<td>"+ t + "</td><td>" +data[t] + "<td>")
}
});
});
</script>
<table class="hovertable table" border="1">
<tr>
<thead>
<th colspan="6">DASHBOARD</th>
</thead>
</tr>
<tbody>
</tbody>
</table>
</html>
Does anyone have any light?