Hans Pede Hans Pede - 3 months ago 5
JSON Question

Inspector show 3 sec update, how do I get newly value?

In index.php I have a javasript, that take JSON data from data.php every 3 sec. Data.php end with this:

echo json_encode($row);

Inspector in index.php shows a couple of objects (which are refreshed each 3 sec). Say 3 rows in DB, then it will look like this:

=>[Object, Object, Object]

I can open the above, and it looks like this:

0: Object
1: Object
2: Object

Each three can be opened again I see my newly updated data (if it change in data.php).

How do I pull out information from those objects, so I can use it live on index.php?

I should probably add the javascript that import data as well:

function populate(){
var items= [];
url: 'data.php',
type: 'GET',
dataType: 'json',

success: function(data){


$.each(data, function(i,v){
items.push('< th >'+v+'< /th >');

error: function(err){


var obj = JSON.parse(object_to_parse);

and then use associative names like if it is from db and there is column name id then you get it by obj.id and so on
maybe then

for(var i=0;i<response_data.length;i++)
  obj = JSON.parse(response_data[i]);
  var new_li = $('<li/>',{ 'text':obj.id });