我试图通过以下方式获取JSON文件:
$.ajax('/file.json', {
contentType: 'application/json',
dataType: 'jsonp',
success: function (data) {
console.log(data);
},
error: function (jqXHR, text, errorThrown) {
console.log(jqXHR + " " + text + " " + errorThrown);
}
});
Run Code Online (Sandbox Code Playgroud)
但是,我总是得到这个错误:
parsererror SyntaxError: Unexpected token :
Run Code Online (Sandbox Code Playgroud)
我的JSON文件非常简单:
{
stuff: "some stuff"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切,我听说过一些跨域的事情,但JSON文件在html的同一目录中.我不知道如何解决它.