2
How do I get the result of a json and play directly inside a td of my table? It’s right in the form of getJSON?
<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>
This is my json:
{
"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 code is all like this, but I haven’t had any success yet.
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type = "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>
Someone has some light?
Doesn’t it work? What’s your HTML like? Have you checked that
data
has content?– Sergio
It doesn’t work. I don’t really know how to call these json values inside td. I tried something like this: <td id="inprog"></td>
– Alisson Cunha