我已经用Fetch获得了GET和POST方法之外的内容.但我找不到任何好的删除和放置示例.
所以,我向你求婚.你能举一个关于DELETE和PUT方法与fetch的好例子吗.解释一下.
我已经用Fetch获得了GET和POST方法之外的内容.但我找不到任何好的删除和放置示例.
所以,我向你求婚.你能举一个关于DELETE和PUT方法与fetch的好例子吗.解释一下.
下面是一个fetch 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);