【发布时间】:2019-01-11 22:52:01
【问题描述】:
几年前我确实有这段代码工作过,最近又回来了,我在网页上有一个 javascript 刷新数据。我使用 json 调用服务器并接收我认为没问题的内容。
我的 python 数据库代码,似乎工作正常。
cur = db.execute('select sensor_name, temp from cur_temps ORDER BY sensor_name')
return jsonify(cur.fetchall())
收到Json
[["BoilerRoom",24.94],["Cylinder1",49.94],["Cylinder2",42.38],["Cylinder3",41.88],["Sensor1",85],["SolidFuelFlow",59],["SolidFuelReturn",41.62]]
我正在尝试获取与 Cylinder2 = 42.38 关联的数字
我之前运行的js代码如下
<script type=text/javascript>
function get_temps() {
$.getJSON("_status",
function (data) {
$('#CylTop').text(data.Cylinder1 + "°")
$('#CylMid').text(data.Cylinder2 + "°")
$('#CylBot').text(data.Cylinder3 + "°")
$('#Solid_flow').text(data.SolidFuelFlow)
$('#Solid_return').text(data.SolidFuelReturn)
$('#BRoom').text(data.BoilerRoom);
console.log(data)
console.log(data.Cylinder1)
}
);
}
setInterval('get_temps()', 5000);
</script>
控制台在浏览器中显示(数据)正常,当我尝试显示其他内容时。 'console.log(data.Cylinder1)' 显示未定义。 我是一个新手,所以我假设一些索引需要作为一个数组发生,但我有点迷失了。 任何指导将不胜感激。
非常感谢
C 达布斯
【问题讨论】:
标签: javascript python arrays flask