简体   繁体   中英

Fetch polyfill, undefined PromiseValue

Trying to make a DELETE request using fetch polyfill, but I get Uncaught TypeError: Cannot read property 'then' of undefined , this is the error on promise.then()

here is how I do it:

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

on the other hand, when I do a /GET request, everything works fine:

function fetchData(url) {    
  return fetch(url).then(response =>
    response.json().then(json => {
      return json;
    })
  );
}

any idea what I am doing wrong?

You must return the promise:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM