Search code examples
jqueryajaxcorsdbpedia

Get dpedia data through cross domain ajax


I am trying to get the JSON data from the link http://dbpedia.org/data/Mountain_View,_California.json. However I am unable to get it, because Access-Control-Allow-Origin header is missing from the response. I have read online that this used to work before.

Here is the code snippet that I am using to get the JSON data --

$.getJSON("http://dbpedia.org/data/Mountain_View,_California.json",
     function(data){
     console.log(data);
});

Solution

  • Try it with JSONP instead.

    $.ajax({
        url: "http://dbpedia.org/data/Mountain_View,_California.json",
        dataType: "jsonp",
        success: function( response ) {
            console.log( response ); 
        }
    });
    

    You can read more about jsonp and jquery here: http://api.jquery.com/jquery.ajax/#data-types