小编典典

Javascript:获取DELETE和PUT请求

reactjs

我已经无法通过Fetch获得GET和POST方法了。但是我找不到任何很好的DELETE和PUT示例。

所以,我要你。您能否举一个使用fetch的DELETE和PUT方法的好例子。并解释一下。


阅读 260

收藏
2020-07-22

共1个答案

小编典典

这是一个获取POST示例。您可以针对进行相同操作DELETE

function createNewProfile(profile) {
    const formData = new FormData();
    formData.append('first_name', profile.firstName);
    formData.append('last_name', profile.lastName);
    formData.append('email', profile.email);

    return fetch('http://example.com/api/v1/registration', {
        method: 'POST',
        body: formData
    }).then(response => response.json())
}

createNewProfile(profile)
   .then((json) => {
       // handle success
    })
   .catch(error => error);
2020-07-22