3

I'm trying to use the example for Jquery-ui autocomplete to work with Freebase. Additionally I'm using the tag-it plugin...

This is what I'm trying but doesn't work:

$(function() {
    $("#tags").tagit({
        tagSource: function( request, response ) {
                        $.ajax({
                            url: "https://www.googleapis.com/freebase/v1/search",
                            dataType: "jsonp",
                            data: {
                                limit: 12,
                                name: request.term
                            },
                            success: function( data ) {
                                response( $.map( data.result, function( item ) {
                                    return {
                                        label: item.name,
                                        value: item.name
                                    }
                                }));
                            }
                        });
        }
    });
});

Using something like: https://www.googleapis.com/freebase/v1/search?query=ambrose%20b&indent=true

Example JSON

{
  "status": "200 OK",
  "result": [
    {
      "mid": "/m/0dkdnj6",
      "name": "Ambrose B. Rathborne",
      "notable": {
        "name": "Author",
        "id": "/book/author"
      },
      "lang": "en",
      "score": 71.059212
    },
    {
      "mid": "/m/0m17",
      "name": "Ambrose Bierce",
      "notable": {
        "name": "Journalist",
        "id": "/m/0d8qb"
      },
      "lang": "en",
      "score": 34.444187
    }.....

From the example which does work:

$(function() {
    $("#tags").tagit({
        tagSource: function( request, response ) {
                        $.ajax({
                            url: "http://ws.geonames.org/searchJSON",
                            dataType: "jsonp",
                            data: {
                                featureClass: "P",
                                style: "full",
                                maxRows: 12,
                                name_startsWith: request.term
                            },
                            success: function( data ) {
                                response( $.map( data.geonames, function( item ) {
                                    return {
                                        label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                        value: item.name
                                    }
                                }));
                            }
                        });
        }
    });
});
ere
  • 1,739
  • 3
  • 19
  • 41

1 Answers1

2

You got it almost right. You have your inputs wrong, try:

$(function() {
    $("#tags").tagit({
        tagSource: function( request, response ) {
                        $.ajax({
                            url: "https://www.googleapis.com/freebase/v1/search",
                            dataType: "jsonp",
                            data: {
                                limit: 12,
                                query: request.term
                            },
                            success: function( data ) {
                                response( $.map( data.result, function( item ) {
                                    return {
                                        label: item.name,
                                        value: item.name
                                    }
                                }));
                            }
                        });
        }
    });
});
holden
  • 13,471
  • 22
  • 98
  • 160