我已经无法通过Fetch获得GET和POST方法了。但是我找不到任何很好的DELETE和PUT示例。
所以,我要你。您能否举一个使用fetch的DELETE和PUT方法的好例子。并解释一下。
这是一个获取POST示例。您可以针对进行相同操作DELETE。
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);