1 Replies - 1579 Views - Last Post: 01 April 2014 - 04:44 AM

#1 bello2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-March 14

how to query Dbpedia in html -javascript

Posted 31 March 2014 - 10:57 PM

Hi , can any one help me to start up. I am new to Dbpedia. I want to design a simple html -javascript to Query the capital city of any given county from Dbpedia. this is what I did but its not responding.

<html>
        <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <style type="text/css">

        </style>
        </head>
        <body></body>
        <script type="text/javascript">
            var url = "http://dbpedia.org/sparql";
            var query = "\
             PREFIX dbpedia2: <http://dbpedia.org/resource/>\
             PREFIX ABs: <http://dbpedia.org/ontology/>\
            SELECT ?capital\
           WHERE {\
                    ?s dbpedia2:India\"@en;\ abs:capital ?capital\ 
            }";


            var queryUrl = encodeURI( url+"?query="+query+"&format=json" );
            $.ajax({
                dataType: "jsonp",  
                url: queryUrl,
                success: function( _data ) {
                    var results = _data.results.bindings;
                    for ( var i in results ) {
                        var res = results[i].capital.value;
                        alert(res);
                    }
                }
            });
        </script>



        </html>


Is This A Good Question/Topic? 0
  • +

Replies To: how to query Dbpedia in html -javascript

#2 andrewsw   User is online

  • blow up my boots
  • member icon

Reputation: 6549
  • View blog
  • Posts: 26,553
  • Joined: 12-December 12

Re: how to query Dbpedia in html -javascript

Posted 01 April 2014 - 04:44 AM

'\' is a non-standard line-continuation character in Javascript and you have to be very careful with whitespace when using it.

Put your query on one long line. Once you've got it working then you can attempt to tidy it by splitting it across a few lines.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1