question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use fetch post json and Sending cookies ?

See original GitHub issue

How are you. I have a question: How to use fetch post json and Sending cookies ? My code:

return fetch('/category/save.json' , {
            credentials: 'include',
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        }).then(function(response){
            if (response.status >= 200 && response.status < 300) {
                return response
            } else {
                var error = new Error(response.statusText);
                error.response = response;
                throw error
            }
        }).then(function(response) {
            return response.json();
        }).then(function(json) {
            console.log('parsed json', json)
        }).catch(function(ex) {            
            console.log('parsing failed', ex)
        });

Why cookie not send? Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
kevin4936commented, Dec 16, 2016

I only use parameter credentials: ‘include’ , The cookie Can send. But I use parameter credentials: ‘include’ and headers: { ‘Content-Type’: ‘application/json’ } to post json data, Why cookie not send?

7reactions
xgqfrms-GitHubcommented, Jun 14, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetch API with Cookie - Stack Overflow
I called POST /api/auth and see that cookies were successfully received. Then calling GET /api/users/ with credentials: 'include' and got 401 ...
Read more >
Using the Fetch API - MDN Web Docs
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses.
Read more >
Sending Cookies With JavaScript Fetch - YouTube
In this video I talk about an issue you may run into when trying to use the fetch function in JavaScript.Need one-on-one help...
Read more >
Cookie missing in HTTP request when using Fetch API
I store a CSRF token in a cookie, which is used by the server to validate client-side HTTP POST requests. The server responds...
Read more >
How to Pass Cookies with Fetch or Axios Requests - Sabe.io
This will make a request to the server at http://example.com/data.json and return the response as a JSON object, then log the data to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found