I need to send a POST fetch request using pure javascript to a Url. I need to add an object to my code that looks like this: var data = {task: ”getall"}
but I don't know where or how to include it or how to start. I'm still very new to Js and I'd like to get some help with this task.
This is my html code for the table:
<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>
And this is my js code for displaying the data:
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;
});
}
In theory I should receive data which can be seen in developer tools network option and than I should display that data on a Html page in a table.