dswy34539 2016-07-08 22:57
浏览 37
已采纳

Inspector显示3秒更新,我如何获得新值?

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= [];
       $.ajax({
       url: 'data.php',
       type: 'GET',
       dataType: 'json',

       success: function(data){

          console.log(data);  

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

          $('#sampleTable').html(items.join(','));
      },
      error: function(err){
          console.log(err.responseText);
      }
   });
   }

   setInterval(function(){
      populate();
   },3000);
  • 写回答

1条回答 默认 最新

  • doubengshao8872 2016-07-08 23:07
    关注
    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 });
      $('#parrent_id').append(new_li);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示