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

前端 未结 30 2072
花落未央
花落未央 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:29

    This might be old. But, it just occurred in angular, the content type for request and response were different in my code. So, check headers for ,

     let headers = new Headers({
            'Content-Type': 'application/json',
            **Accept**: 'application/json'
        });
    

    in React axios

    axios({
      method:'get',
      url:'http://  ',
     headers: {
             'Content-Type': 'application/json',
            Accept: 'application/json'
        },
      responseType:'json'
    })
    

    jQuery Ajax:

     $.ajax({
          url: this.props.url,
          dataType: 'json',
    **headers: { 
              'Content-Type': 'application/json',
            Accept: 'application/json'
        },**
          cache: false,
          success: function (data) {
            this.setState({ data: data });
          }.bind(this),
          error: function (xhr, status, err) {
            console.error(this.props.url, status, err.toString());
          }.bind(this)
        });
      },
    

提交回复
热议问题