1

I am baffled by one particular problem. I am trying to set a cookie using the fetch api but I am unable to do so.

static deleteorder = (domain = "http://localhost:8080/pc", order) => {

  let cooks = "JSESSIONID=AFAFWEEVV2323GG";
  fetch(deleteorder, {
      method: `GET`,
      credentials: 'same-origin',
      headers: {
        "Content-type": `application/x-www-form-urlencoded`,
      },

    })
    .then(res => {
      console.log(res.status);
    })
    .catch(error => {
      console.log(error);
    });
};
}

When The function runs and 200 is returned but the data remains the same meaning the order remains. Can one of you shed some light? I am in the beginner phase of learning the fetch api so any feedback would be greatly appreciated.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Roosevelt H
  • 340
  • 3
  • 11

1 Answers1

6

Fetch() simply sends the current document's cookies, so just add the cookie to document.cookie.

static deleteorder = (domain = "http://localhost:8080/pc", order) => {

  document.cookie = "JSESSIONID=AFAFWEEVV2323GG";
  fetch(deleteorder, {
      method: `GET`,
      credentials: 'same-origin',
    })
    .then(res => {
      console.log(res.status);
    })
    .catch(error => {
      console.log(error);
    });
};
Barmar
  • 741,623
  • 53
  • 500
  • 612