【发布时间】:2019-07-07 23:15:56
【问题描述】:
我需要使用纯 javascript 向 Url 发送 POST 获取请求。我需要在我的代码中添加一个对象,如下所示:var data = {task: ”getall"} 但我不知道在哪里或如何包含它或如何开始。我对 Js 还是很陌生,我想在这项任务上获得一些帮助。
这是我的表格 html 代码:
<div>
<input id="postall" type="button" value="POST Users" />
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Street</th>
<th>House Number</th>
</tr>
</thead>
<tbody id="userTablePost"></tbody>
</table>
这是我用于显示数据的 js 代码:
function renderUsers(users) {
const tbody = document.getElementById("userTablePost");
users.forEach(user => {
let row = tbody.insertRow();
let cell = row.insertCell();
cell.textContent = user.id;
cell = row.insertCell();
cell.textContent = user.name;
cell = row.insertCell();
cell.textContent = user.street;
cell = row.insertCell();
cell.textContent = user.house_number;
});
}
理论上,我应该收到可以在开发者工具网络选项中看到的数据,然后我应该在表格中的 Html 页面上显示该数据。
【问题讨论】:
标签: javascript html post request fetch