Changeset 27745 for gs2-extensions


Ignore:
Timestamp:
2013-07-04T09:16:55+12:00 (11 years ago)
Author:
davidb
Message:

Javascript code to load an AJAX call to the Sparql-endpoint into a textarea

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/afrepo/trunk/src/src/html/sparql.php

    r27693 r27745  
    2121    function onSubmit() {
    2222
    23       alert("OnSubmit");
    24 
    2523      $.ajax({
    26           type: "POST",
     24          type: "GET",
     25       
    2726      beforeSend: function (request) {
    2827        //request.setRequestHeader("Authority", authorizationToken);
     28        //request.setRequestHeader("origin", "http://nema.lis.illinois.edu");
     29        },
     30
     31      url: "<?php echo $repo->getSparqlEndpoint();?>",
     32        data: { "query": $('#rdf-query').val(), "output": $('#rdf-output').val() },
     33        //processData: false,
     34
     35        /*
     36      xhrFields: {
     37        withCredentials: true
     38      },
     39      crossDomain: true,
     40        */
     41
     42        // accepts: "text/plain",
     43        //converters: {},
     44        dataType: "text",
     45
     46      success: function(msg) {
     47        //var $msg = $(msg);
     48        //alert("msg = " +msg);
     49
     50        //$('#rdf-results').val(msg.documentElement.outerHTML);
     51        $('#rdf-results').val(msg);
    2952      },
    3053
    31       url: "<?php echo $repo->getSparqlEndpoint();?>",
    32       data: "query=" + $('#rdf-query'),
    33       processData: false,
    34       success: function(msg) {
    35         $("#rdf-results").append("The result =" + StringifyPretty(msg));
    36     }
     54
     55    error: function(err) {
     56        alert(err.toString());
     57        if (err.status == 200) {
     58          ParseResult(err);
     59        }
     60        else { alert('Error:' + err.responseText + '  Status: ' + err.status); }
     61      }
     62
    3763      });
    3864
     
    88114   <span style="margin: 5px 20px 5px 20px;">
    89115     Output type:
    90      <select name="output">
     116     <select name="output" id="rdf-output">
    91117       <option>xml</option>
    92118       <option>json</option>
Note: See TracChangeset for help on using the changeset viewer.