尝试使用fetch polyfill发出DELETE
请求,但我得到Uncaught TypeError: Cannot read property 'then' of undefined
,这是promise.then()
上的错误
这是我如何做到的:
function deleteData(item, url) {
fetch(url + '/' + item, {
method: 'delete'
}).then(response => {
return response.json();
});
}
另一方面,当我执行/GET
请求时,一切正常:
function fetchData(url) {
return fetch(url).then(response =>
response.json().then(json => {
return json;
})
);
}
知道我做错了什么?
答案 0 :(得分:3)
你必须回复承诺:
function deleteData(item, url) {
return fetch(url + '/' + item, {
method: 'delete'
}).then(response => {
return response.json();
});
}