“SyntaxError: Unexpected token < in JSON at position 0”

前端 未结 30 1579
花落未央
花落未央 2020-11-22 04:39

In a React app component which handles Facebook-like content feeds, I am running into an error:

Feed.js:94 undefined \"parsererror\" \"SyntaxError: Un

30条回答
  •  长发绾君心
    2020-11-22 05:15

    The wording of the error message corresponds to what you get from Google Chrome when you run JSON.parse('<...'). I know you said the server is setting Content-Type:application/json, but I am led to believe the response body is actually HTML.

    Feed.js:94 undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0"

    with the line console.error(this.props.url, status, err.toString()) underlined.

    The err was actually thrown within jQuery, and passed to you as a variable err. The reason that line is underlined is simply because that is where you are logging it.

    I would suggest that you add to your logging. Looking at the actual xhr (XMLHttpRequest) properties to learn more about the response. Try adding console.warn(xhr.responseText) and you will most likely see the HTML that is being received.

提交回复
热议问题