获取polyfill,undefined PromiseValue

时间:2015-06-02 12:24:36

标签: javascript reactjs promise es6-promise

尝试使用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;
    })
  );
}

知道我做错了什么?

1 个答案:

答案 0 :(得分:3)

你必须回复承诺:

function deleteData(item, url) {
  return fetch(url + '/' + item, {
    method: 'delete'
  }).then(response => {
    return response.json();
  });
}