- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用 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;
})
);
}
知道我做错了什么吗?
最佳答案
您必须返回 promise :
function deleteData(item, url) {
return fetch(url + '/' + item, {
method: 'delete'
}).then(response => {
return response.json();
});
}
关于javascript - 获取 polyfill,未定义的 PromiseValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30596004/
我目前在第一次使用 Promise.all() 时遇到问题(两种获取方法)。 目前,当我在控制台记录我的响应时,我可以在响应中看到我试图在 promiseValue 下获取的数据。但我不确定如何访问它
我试图显示client模式中的信息详细信息。点击@click="showDetails(props.row.id)"后. 我正在使用axios.get在方法中并返回数据。现在,它将数据作为 Promi
我是 React-Redux 的新手。我正在对 json 文件进行 api 调用,并希望将此文件的内容作为数组返回。我没有太多地处理 Promises,所以我对访问它们的知识有点模糊。基本上,这就是我
尝试使用 fetch polyfill 发出 DELETE 请求,但我得到 Uncaught TypeError: Cannot read property 'then' of undefined,这
我正在尝试返回 json 对象数组,但下面的代码返回 [[PromiseValue]] 并且数据肯定在那里。 “函数的结果” 如何获取 json 对象数组并将其设置为状态 注意:如果我在 getEnd
我已经搜索了 StackOverflow 并阅读了有关从返回的 Promise 获取值的主题,但由于某种原因,这些示例对我不起作用。 我的代码: const getThatZip = (zip) =>
情况是:我有一个城市数组,函数getCityForecast获取每个城市的天气预报,并将接收到的转换后的数据返回为所需的格式。我需要将它们保存到数组中,并将该数组保存在组件的state中。 this.
下午好。我是 Firebase batabase 的新手。请告诉我如何从我的数据库中获取数据以便进一步与他们合作。现在我的函数返回 Promise {} 以及 PromiseValue 中我需要的日期
我是一名优秀的程序员,十分优秀!