【发布时间】:2015-08-16 05:47:08
【问题描述】:
尝试使用 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;
})
);
}
知道我做错了什么吗?
【问题讨论】:
-
我不确定我的回答是否正确,因为你不知道你在哪里得到错误(你 需要
return但也许你得到另一个之前的错误)。 -
完美运行。编码太多小时,需要休息一下,再次感谢!
标签: javascript reactjs promise es6-promise