首页 文章

通过Javascript查询GraphDB时指定结果MIME类型(RDF4J Server REST API)

提问于
浏览
1

我正在尝试使用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);

但我得到这个错误:

拒绝从'http:// localhost:7200 / repositories / myRepo?callback = jQuery321005935533972872964_1529595202948&query = ...'执行脚本,因为其MIME类型('text / csv')不可执行 .

如果我通过Chrome的开发人员工具检查请求,我可以在“应用程序”选项卡下看到预期的CSV序列化结果集(!?)

有没有办法告诉GraphDB / RDF4J将结果集序列化为JSON或在ajax请求中管理这样的CSV序列化?

1 回答

  • 1

    通过使用 -Dgraphdb.workbench.cors.enable=true 启动graphDB并删除 dataType: 'jsonp' 来解决

相关问题