close

[Solved] undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing following error To Solve undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0 Error in reactJs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0 Error Occurs ?

I have a simple function that is to make API calls and set data But unfortunately, I am facing this error.

undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0

Here is my API call function

getUserData : function getUserData() {
    $.ajax({
      url: this.props.url,
      dataType: 'json',
      success: function (data) {
        this.setState({ data: data });
      }.bind(this),
      error: function (xhr, status, err) {
        console.error(this.props.url, status, err.toString());
      }.bind(this)
    });
  },

How To Solve undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0 Error ?

  1. How To Solve undefined “parsererror” “SyntaxError: Unexpected token

    To Solve undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0 Error Here You're receiving HTML or XML back from the server but the dataType: json is telling jQuery to parse as JSON. Check the “Network” tab in Chrome dev tools to see contents of the server's response. I Just facing the same issue And I Just removed the dataType:'json' from the $.ajax method and my issue was solved.

  2. undefined “parsererror” “SyntaxError: Unexpected token

    To Solve undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0 Error Here You're receiving HTML or XML back from the server but the dataType: json is telling jQuery to parse as JSON. Check the “Network” tab in Chrome dev tools to see contents of the server's response. I Just facing the same issue And I Just removed the dataType:'json' from the $.ajax method and my issue was solved.

Solution 1

  1. Here You’re receiving HTML or XML back from the server
  2. but the dataType: json is telling jQuery to parse as JSON.
  3. Check the “Network” tab in Chrome dev tools to see contents of the server’s response.

Solution 2

I was getting this running webpack, and it turned out to be some corruption somewhere in the local node_modules dir, and was enough to get it working right again.

rm -rf node_modules
npm install

Solution 3

I Just facing the same issue And I Just removed the dataType:’json’ from the $.ajax method and my issue was solved.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment