How Do I set a cookie in fetch request?

Roosevelt H

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

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);
    });
};

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I detect requests initiated by the new fetch standard? How should I detect an AJAX request in general?

分類Dev

How do I get a fetch request to return the number of objects in the persistent store?

分類Dev

How do I install the request class in Flask?

分類Dev

How do i send form data to php using fetch in nativescript?

分類Dev

How do I redirect a user after login with fetch()

分類Dev

How do I make a GET request with JSON in the request body

分類Dev

How do I prevent the "cookie associated with a cross-site resource set without SameSite attribute" warning when making AJAX Cross origin requests?

分類Dev

How do I set a mock date in Jest?

分類Dev

How do I set up PreAuthenticationAuthenticationProvider?

分類Dev

How do I set up PreAuthenticationAuthenticationProvider?

分類Dev

How do I set an environment variable?

分類Dev

How do I set the ServiceStack ResponseStatus StatusCode?

分類Dev

How do I set an array ? (JAVA classes)

分類Dev

How do I set themes for widgets in windows?

分類Dev

How Do I Correctly Set a getElementById Object?

分類Dev

How do I set "StyleBoxEmpty" on buttons in Godot?

分類Dev

How do I set setReverseLayout() in my code?

分類Dev

How do I set a timer for a Parse object?

分類Dev

how do I set keys for JSONObjects in PHP

分類Dev

How do I permanently set the affinity of a process?

分類Dev

How do I set up a virtual host?

分類Dev

How do I set up a xen bridge?

分類Dev

How do I set frame alignment?

分類Dev

How do I set up DataTables?

分類Dev

How do I set deault browser to NOT rekonq?

分類Dev

How can I set param as not required in micronaut GET request?

分類Dev

Spring Security: How can I set a RememberMe cookie url path, that differs from the context path?

分類Dev

how to stop function if a fetch request fails

分類Dev

How do I enable remote access/request in Elasticsearch 2.0?

Related 関連記事

  1. 1

    How do I detect requests initiated by the new fetch standard? How should I detect an AJAX request in general?

  2. 2

    How do I get a fetch request to return the number of objects in the persistent store?

  3. 3

    How do I install the request class in Flask?

  4. 4

    How do i send form data to php using fetch in nativescript?

  5. 5

    How do I redirect a user after login with fetch()

  6. 6

    How do I make a GET request with JSON in the request body

  7. 7

    How do I prevent the "cookie associated with a cross-site resource set without SameSite attribute" warning when making AJAX Cross origin requests?

  8. 8

    How do I set a mock date in Jest?

  9. 9

    How do I set up PreAuthenticationAuthenticationProvider?

  10. 10

    How do I set up PreAuthenticationAuthenticationProvider?

  11. 11

    How do I set an environment variable?

  12. 12

    How do I set the ServiceStack ResponseStatus StatusCode?

  13. 13

    How do I set an array ? (JAVA classes)

  14. 14

    How do I set themes for widgets in windows?

  15. 15

    How Do I Correctly Set a getElementById Object?

  16. 16

    How do I set "StyleBoxEmpty" on buttons in Godot?

  17. 17

    How do I set setReverseLayout() in my code?

  18. 18

    How do I set a timer for a Parse object?

  19. 19

    how do I set keys for JSONObjects in PHP

  20. 20

    How do I permanently set the affinity of a process?

  21. 21

    How do I set up a virtual host?

  22. 22

    How do I set up a xen bridge?

  23. 23

    How do I set frame alignment?

  24. 24

    How do I set up DataTables?

  25. 25

    How do I set deault browser to NOT rekonq?

  26. 26

    How can I set param as not required in micronaut GET request?

  27. 27

    Spring Security: How can I set a RememberMe cookie url path, that differs from the context path?

  28. 28

    how to stop function if a fetch request fails

  29. 29

    How do I enable remote access/request in Elasticsearch 2.0?

ホットタグ

アーカイブ