我的HTML
文件如下:
Sum: <div id="sum">?</div>
以及类似的JavaScript,如下所示:
function refresh(){
//Wait for request from Amazon Gateway API, then replace 'sum' with result of
Python function
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://8qp45dk604.execute-api.us-east- 1.amazonaws.com/beta", true);
xhttp.send();
xhttp.addEventListener("readystatechange", processRequest, false);
function processRequest(e){
if(xhttp.readyState == 4 && xhttp.status == 200){
var response = JSON.parse(xhttp.responseText);
var a = response.a;
var b = response.b;
document.getElementById("sum").innerHTML =
resultOfPythonFunction('sum.py', 'sum', a, b);
}
}
setTimeout(refresh, 3000);
}
为了用Python resultOfPythonFunction('sum.py', 'sum', a, b);
函数的结果来修改div
,我应该用什么替换行sum
?