【发布时间】:2018-11-30 19:24:14
【问题描述】:
我想每隔一段时间更新我的 HTML 页面,从我的 Express API 中检索数据。
但是,我很难将任何此类功能集成到 Pug 中。 fetch 和 XMLHttpRequest 都产生相同的错误:
错误:“获取不是函数”
我尝试将函数放入外部 JavaScript 文件 - 同样的问题。
body
p Welcome
-
function httpGet(theUrl)
{
fetch(theUrl)
.then(function(response) {
return response.json();
})
}
p= httpGet('http://localhost:3000/test')
【问题讨论】:
-
这看起来像您正在尝试调用
fetch服务器端。你确定要那个吗?
标签: javascript node.js express pug fetch-api