The results from named queries can be accessed using JavaScript in the following three ways.

Retrieving the results formatted as SPARQL results XML

To retrieve the results, send a GET request to the Named Query URI with the suffix ?results. This will return the tuple binding results in an XML document.

Retrieving the results formatted in HTML, CSV, TSV, or JSON

To retrieve the result in HTML, CSV, TSV, or JSON use the suffix: ?results&tqx=out:html , ?results&tqx=out:csv , ?results&tqx=out:tsv-excel, or ?results&tqx=out:table respectively.

All result formats comply with the GoogleChartToolsDatasourceProtocol.

Accessing the results from a Web browser

To access the result from a Web browser, use the google Query library to parse the result, as shown below.

  <script src="https://www.google.com/jsapi" type="text/javascript"> </script>
  <script type="text/javascript">
    // <![CDATA[
    google.load("visualization", "1.0", {callback:function() {
      new google.visualization.Query("organizations-by-country.rq?results").send(function(result){
        var select = $('#my-select');
        var data = result.getDataTable();
        var rows = data.getNumberOfRows();
        for (var i=0; i<rows; i++) {
          var option = $('<option/>');
          option.text(data.getValue(i, 0));
          select.append(option);
        }
      });
    }});
    // ]]>
  </script>

Take notice that this code relies on jQuery placing the results into an HTML element with an ID of "my-select". This ID can be whatever you want, but it must be present in the HTML for the jQuery to succeed. In this case, the HTML element that is necessary is:

<div id="my-select"> 
  ... 
</div>