1

尝试DELETE使用 fetch polyfill 发出请求,但我得到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;
    })
  );
}

知道我做错了什么吗?

4

1 回答 1

3

您必须返回承诺:

function deleteData(item, url) {
  return fetch(url + '/' + item, {
    method: 'delete'
  }).then(response => {
    return response.json();
  });
}
于 2015-06-02T12:25:55.193 回答