我有一个HTML页面,如下所示:
<!DOCTYPE html>
<script>
const aircraft_refresh_interval = setInterval("aircraft()",15000);
function aircraft() {
fetch('/refresh_aircraft')
.then(response => response.json())
.then(json => {
console.log(json);
document.getElementById("demo").innerHTML = json.num_aircraft
})
}
</script>
<html>
<head>
<title>Aircraft</title>
</head>
<body onload="aircraft()">
<p>There are currently <span id="demo"></span> aircraft around</p>
<button onclick="aircraft()">Manual Refresh</button>
</body>
</html>
function aircraft()函数每15秒从我的python烧瓶后端获取一个JSON。
我的问题是,我是否可以将返回的json作为变量传递给HTML页面,以便在整个页面中使用该json的元素?(可能是在忍者片段中?
例如,我想在一行上打印<p>There are currently {{json.num_aircraft }} aircraft around</p>,而在另一行上我想打印<p>The maximum range today is {{json.max_range}}</p>
我尝试在函数中使用return,但我认为我使用了错误的语法。