gpt4 book ai didi

javascript - 获取 polyfill,未定义的 PromiseValue

转载 作者:行者123 更新时间:2023-11-30 12:22:21 25 4
gpt4 key购买 nike

尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com