ServerSide(app.js):
我从DB获取一些数据并将其放入数组
app.post('/sendform', (req,res) =>{
var array = [{"h":"1"},{"e","2"}];
res.send(array);
)}
ClientSide(client.js):
我想获取该数组并将其添加到我的index.html
function tableContent(){
fetch('/')
.then(res => {
console.log(res);
if(res.ok) return res.json();
});
.then(data => {
//do something with html file
});
}
答案 0 :(得分:0)
var URL = “127.0.0.1:3000/sendform”;
var req = new Request(URL, {method: 'POST', cache: 'reload'});
fetch(req).then(function(response) {
var reader = response.body.getReader();
return reader.read();
}).then(function(result, done) {
if (!done) {
// do something with each chunk
}
});
POST方法请求您的地址