In a React app component which handles Facebook-like content feeds, I am running into an error:
Feed.js:94 undefined \"parsererror\" \"SyntaxError: Un
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)
});
},
just something basic to check, make sure you dont have anything commented out in the json file
//comments here will not be parsed and throw error
The possibilities for this error are overwhelming.
In my case, I found that the issue was adding the homepage
filed in package.json
caused the issue.
Worth checking: in package.json
change:
homepage: "www.example.com"
to
hompage: ""
In my case, I was getting this running webpack, and it turned out to be some corruption somewhere in the local node_modules dir.
rm -rf node_modules
npm install
...was enough to get it working right again.
For me, this happened when one of the properties on the object I was returning as JSON threw an exception.
public Dictionary<string, int> Clients { get; set; }
public int CRCount
{
get
{
var count = 0;
//throws when Clients is null
foreach (var c in Clients) {
count += c.Value;
}
return count;
}
}
Adding a null check, fixed it for me:
public Dictionary<string, int> Clients { get; set; }
public int CRCount
{
get
{
var count = 0;
if (Clients != null) {
foreach (var c in Clients) {
count += c.Value;
}
}
return count;
}
}
This might cause due to your javascript code is looking at some json response and you received something else like text.