1
我有这个JavaScript函数,它的目的是在一个属于project
数据集的命名图中插入一个关键字。Jena Fuseki在从javascript进行插入查询时不工作。没有更新参数错误
function insert(keyword) {
var query = "INSERT DATA {GRAPH <http://test1> {<subj> <pred>'" + keyword + "'. }}";
var endpoint = "http://localhost:3030/project/update";
sparqlQueryJson(query, endpoint, showResults, true);
}
我已经执行了Jena Fuseki的--update
选项。该sparqlQueryJson功能如下:
function sparqlQueryJson(queryStr, endpoint, callback, isDebug) {
var querypart = "query=" + escape(queryStr);
// Get our HTTP request object.
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Code for older versions of IE, like IE6 and before.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert('Perhaps your browser does not support XMLHttpRequests?');
}
// Set up a POST with JSON result format.
xmlhttp.open('POST', endpoint, true); // GET can have caching probs, so POST
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.setRequestHeader("Accept", "application/sparql-results+json");
// Set up callback to get the response asynchronously.
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
// Process the results
callback(xmlhttp.responseText);
} else {
// Some kind of error occurred.
alert("Sparql query error: " + xmlhttp.status + " " + xmlhttp.responseText);
}
}
};
xmlhttp.send(querypart);
};
的showResults功能,在我看来,不是在这里非常重要,因为它需要查询的结果,并显示在HTML。
我跟着讨论了here和here,使用http://localhost:3030/project/update
执行查询。问题是,如果我使用Web在具有相同端点URL的本地Fuseki服务器上执行相同的查询,它可以工作,但是从JavaScript代码中,它会引发错误: “SPARQL查询错误:400错误400 :SPARQL更新:无'update ='参数“。 我使用Ubuntu 16.04和Jena Fuseki - 版本2.4.1。