我正在尝试使用 Javascript 查询 GraphDB 存储库。这是代码:
var SPARQLendpoint = {
getData: function (query) {
var endpointUrl = 'http://localhost:7200/repositories/myRepo',
settings = {
headers: { Accept: 'application/sparql-results+json'},
data: { query: query },
dataType: 'jsonp'
};
$.ajax(endpointUrl, settings).then(function (data) {
$('body').append(($('<pre>').text(JSON.stringify(data))));
console.log(data);
});
});
}
}
query = 'here is the query';
SPARQLendpoint.getData(query);
但是我得到这个错误:
Refused to execute script from 'http://localhost:7200/repositories/myRepo?callback=jQuery321005935533972872964_1529595202948&query=...' because its MIME type ('text/csv') is not executable.
如果我通过 Chrome 的开发者工具检查请求,我可以在“应用程序”选项卡下看到预期的 CSV 序列化结果集(!?)
有没有办法告诉 GraphDB/RDF4J 将结果集序列化为 JSON 或在 ajax 请求中管理这样的 CSV 序列化?
最佳答案
通过使用 -Dgraphdb.workbench.cors.enable=true
启动 graphDB 并从 JS 代码中删除 dataType: 'jsonp'
解决
关于javascript - 通过 Javascript(RDF4J Server REST API)查询 GraphDB 时指定结果 MIME 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50972635/