I'm trying to get a JSON file via:
$.ajax('/file.json', {
contentType: 'application/json',
dataType: 'jsonp',
success: function (data) {
console.log(data);
},
error: function (jqXHR, text, errorThrown) {
console.log(jqXHR + " " + text + " " + errorThrown);
}
});
However, I always get this error:
parsererror SyntaxError: Unexpected token :
My JSON file it's very simple:
{
stuff: "some stuff"
}
I've tried everything, I heard about some cross-domain thing but the JSON file is in the same directory of the html. I don't know how to fix it.
Change stuff:
to "stuff":
this is correct json Syntax.
Try changing it to:
$.ajax({
url: 'file.json',
contentType: 'application/json',
dataType: 'json',
success: function (data) {
console.log(data);
},
error: function (jqXHR, text, errorThrown) {
console.log(jqXHR + " " + text + " " + errorThrown);
}
});
But it looks maybe some bad JSON is being returned. Try a different JSON file which you are certain is valid?
Also if the file.json is in same directly, ditch including the '/' before file.json. Unless you're running it from a virtual host or the web servers root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With