Answer the question
In order to leave comments, you need to log in
How to correctly process JSON data?
I have JSON data in the following format:
{
0: "1",
1: "0.39578100 1412014767",
2: "755097411bb87a6a5894e39d9aac3bc4",
3: "2",
4: "0.43935900 1412014767",
5: "2cab74f361f62e1f0bca2f593072e8db",
/* ... */
}
<tr id="1"><td> </td><td> </td><td> </td></tr>
<tr id="2"><td> </td><td> </td><td> </td></tr>
<!-- ... -->
$.getJSON(
"server.php",
{
param1: static_rows
},
onAjaxSuccess
);
function onAjaxSuccess(data) {
$.each(data, function(key, val){
items.push(' ');
$("#info").html(s);
});
}
Answer the question
In order to leave comments, you need to log in
1. You cannot start a property name with a number. In your case you need nested arrays of the form
{
"t1": [
"1",
"0.39578100 1412014767",
"755097411bb87a6a5894e39d9aac3bc4"
],
"t2": [
"2",
"0.43935900 1412014767",
"2cab74f361f62e1f0bca2f593072e8db"
]
}
<tr id="t1"><td></td><td></td><td></td></tr>
<tr id="t2"><td></td><td></td><td></td></tr>
function onAjaxSuccess(data) {
$.each(data, function(key, rowData) {
var cells = $('#' + key).find('td');
$.each(rowData, function(index, value) {
cells.eq(index).html(value);
});
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question