Here is a sample example showcasing how to insert triples in Virtuoso Quad store using Digest Authentication in a simple HTML 5 form with embedded AJAX:
This example demonstrates how Virtuoso user can insert triples into the Virtuoso Quad Store using Digest authentication against the Virtuoso "/sparql-auth" endpoint. The implementation is done on the base of simple html form using HTML 5 and AJAX:
<html lang="en">
...
<script type="text/javascript">
function authenticate()
{
vgraphuri = document.demo.graphuri.value ;
vsubject = document.demo.subject.value ;
vpredicate = document.demo.predicate.value ;
vobject = document.demo.object.value ;
vuser = document.demo.username.value ;
vpassword = document.demo.userpassword.value ;
var q = "INSERT INTO GRAPH " + vgraphuri + " { " + vsubject + " " + vpredicate + " " + vobject + " . } " ;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
alert(xhr.responseText);
}
if (xhr.readyState==4 && xhr.status==401)
{
alert("Error: Invalid credentials or insufficient rights to perform the operation.");
}
if (xhr.readyState==4 && xhr.status==500)
{
alert(xhr.responseText);
}
if (xhr.readyState==4 && xhr.status==400)
{
alert(xhr.responseText);
}
}
xhr.open("POST", "/sparql-auth/", false, vuser, vpassword);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send("query=" + encodeURIComponent (q));
};
</script>
...
Steps:






