Two caveats : first, if someone else is hosting the store, you may have to bug them to look at CORS to get around same origin policy issues. Second, I’m not really that experienced with jQuery etc, so chances are my code is far from optimal.
Ok, first, a screenshot :
How it works
Line 46 composes a URL for the query (I’m running against a Fuseki store, it likes “&output=xml”).
The other thing is that this technique isn’t limited to SPARQL (GET) queries. SPARQL 1.1 Update can just as easily be done (e.g. with buttons hooked to Ajax POSTs). There’s an example here (around line 181).
Lines 48-62 aren’t app-specific, it’s just to show one of those whirly things while the data is being retrieved from the store.
Next comes getLinks(), the operational bit of the code. It does an Ajax GET on the URL created above, then processes the XML results. Depending on the store you might have to do a bit of trial & error on the headers (around line 67).
The XML results format is fairly trivial, though when I first thought about this, I expected to need a relatively full-blown XML parser. Nope, jQuery is really handy in this regard. Line 87 grabs all the <result> blocks and loops through them. Then to pull out each value,
there’s e.g. line 91 :
href = $(this).text().trim();