weixin_33738578 2019-07-14 09:41 采纳率: 0%
浏览 72

用ajax更新一个div

I'm trying to update an h3 with the id data using Ajax. The Ajax uses a get request to retrive data from an API, but for some reason the html is not being updated.

This is what the json data looks like {ticker: "TEST", Price: 7876}

I tried to change $('#data').text(data[0].data[]); to $('#data').text(data[ticker].data[]);, for example, but it didn't work either.

I added a console.log(data[0]) to debug it, and the data normally appears in my console.

function doPoll(){

    $.get('http://localhost:8000/tst/', function(data) {
        console.log(data[0]);
        $('#data').text(data[0].data);
        setTimeout(doPoll, 1000);
    });
} 

doPoll();

And this is the html part to be updated:

<h3 id="data"></h3>

Basically instead of that h3 there should be my data updated every tot seconds, but at the actual moment nothing appears.

  • 写回答

4条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有人用过颜色传感器吗?
      • ¥50 求一个SQL长料切短料的优化排版算法
      • ¥15 python 删除TXT文档中小写字母
      • ¥15 ValueError: not enough values to unpack (expected 2, got 0)
      • ¥15 js怎么禁止修改域名
      • ¥15 Cursor为什么在Windows11打不开
      • ¥30 java调用javacv遇到的问题
      • ¥15 如何使用matlab画出带宽100Khz,时长100ms信号的LFM形式的时频图啊
      • ¥15 Error: [BABEL]: Cannot find module '@vue/babel-preset-app'.报错,求解
      • ¥15 --==关于启动加载mount命令的解决方案==--