开发者

Not able to get HTTP GET for Freebase search url

I am using freebase search url to know about query classification. I have send jquery request in javascript as follows, but i am not getting any response.

var searchvalue = document.getElementById("searchtext").value; var url = "http://ww开发者_如何学编程w.freebase.com/api/service/search?query=india"; $.getJSON(url,function(data){alert(data)});

If I place url (http://www.freebase.com/api/service/search?query=india) in browser I am able to get JSON response. Is any one faced this problem.

Thanks, Sathi


You won't be able to use $.getJSON because of browsers' same origin policy. However, most freebase.com apis support JSONP so you should be able to do this:

$.ajax({
  url: "http://api.freebase.com/api/service/search"
  data: {query:"india"},
  dataType: "jsonp",
  success: function(data) {
    console.log("success", data);
  }
});


daepark's answer is correct, you should just remember to place a comma at the end of 'url' If you want a copy-paste solution, here it is:

$.ajax({
        url: "http://api.freebase.com/api/service/search",
        data: {query:"india"},
        dataType: "jsonp",
        success: function(response) {
            alert(response.result.map(
                function(result){
                    return result.name;
                }).toString());
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜