Skip to content
Advertisement

SyntaxError: Unexpected token ” in JSON at position 0 at JSON.parse

I am not able to clearly Identify the bug, data is send in JSON Format still it is showing unusual error

Forgot Password Route

JavaScript

forgotPassword Action.js

JavaScript

As mentioned in some answers online available I have made few changes but Error is still their,

  1. In Action.js I have written content type as “application/json”.
  2. in forgotPassword Route while sending email to function, I have used a method JSON.stringify.

Advertisement

Answer

Your axios.post statement sends a request whose body is an email address (i.e., plain text), but the Content-Type: application/json wrongly claims it to be JSON. That leads to the observed error.

Correct would be

JavaScript

(Note the absence of braces around data.)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement