Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

javascript - Updating page content after Fetch from Client side - Express

I have a list of items being displayed on screen. How do I update the content on the page to reflect a successful delete request? The request is being called using fetch as follows:

function deleteItem(itemId) {
    fetch('http://localhost:3000/' + itemId, {
        method: 'DELETE'
    })
        .then(res => {
            console.log(res);
        });
}

and this is the delete request:

router.delete('/:id', function (req, res){
    let index = parseInt(req.params.id);
    items.splice(index, 1);

    console.log(items);

    return res.status(200);
});

I have tried sooo many things, and none seem to be working. I am using Express/Node.js for this project. Redirecting to the '' on the server-side is not working, and neither in the fetch. Both are giving me different errors. I have looked all over to find solutions but I haven't found a concrete answer that solves my problem.

Error when redirecting from fetch: res.redirect is not a function

Error when redirecting from DELETE on the server side: DELETE http://localhost:3000/ 404 (Not Found)

A redirect from a POST request using a form works perfectly. However, I cannot seem to get the DELETE request to work. Please help!!

question from:https://stackoverflow.com/questions/65877300/updating-page-content-after-fetch-from-client-side-express

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...