delete added

This commit is contained in:
TypoMustakes
2024-04-23 17:46:44 +02:00
parent 4b20644236
commit d981b8afa0
2 changed files with 25 additions and 2 deletions

View File

@@ -18,6 +18,7 @@
<tr>
<th>ID</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="resultarea">

View File

@@ -10,7 +10,10 @@ async function getCustomers()
console.log(customers);
display();
});
}
} customers.forEach(customer => {
})
function display()
{
@@ -22,6 +25,8 @@ function display()
+ t.id +
'</td><td>'
+ t.name +
'</td><td>'
+ '<button type="button" onclick="deleteCustomer(' + t.id + ')">Delete</button>' +
'</td></tr>';
});
}
@@ -33,7 +38,24 @@ function addCustomer()
fetch('https://localhost:5001/api/Customer', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: customerName })
body: JSON.stringify({
name: customerName,
})
})
.then(response => response)
.then(data =>
{
console.log("Success: ", data)
getCustomers();
})
.catch(error => console.error("Error: ", error));
}
function deleteCustomer(id)
{
fetch('https://localhost:5001/api/Customer/' + id, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
})
.then(response => response)
.then(data =>