Json error while trying fect API in javascript

Hello. I need to include the javascript fetch API in my document but I’m getting an error. Pls check the images

It looks to me that first you are getting an error because you are trying to fetch a url that you’re not supposed to (possibly doesn’t exist) and then you are getting an error because you are trying to parse json that isn’t there. They should both be addressed.

It’s hard to debug without using the code. My first question would be if that is the right url? Can you hit it with postman? Should there be a prefix pointing to the server (maybe not, depending on what is going on here)? Should there be that last “/” at the end of fetch('/update-cart/', {?

Thank you for the response. The last “/” has to be included because I have APPEND_SLASH set. The issue shows “CSRF token missing or incorrect” and I have CSRF token loaded in my HTML file. It also showed that CSRF is available when I did console.log(csrftoken) in javascripe but I dont know why I’m getting this error.

And is it getting a token from the cookie? Since I don’t have access to the code and a running example. you’re going to have to debug this.

My philosophy of debugging is this - find a point where the code is doing what you expect and then move forward until it is not doing what you expect. Can you console log that token?

Hi Kevin. Thanks again for the response. I did console log the token in line 27 and 36. Both were generated and I’m still getting a “missing or incorrect CSRF token” in the terminal. Do I have to upload the codes here?

Unfortunately, I’m not a python/django guy, but it sounds like there is some kind of disconnect there. I might recommend finding a forum of people that specialize in python servers.