2012-02-27 3 views
3

Jquery-ui 자동 완성을위한 예를 Freebase에서 사용하려고합니다.freebase 및 jsonp로 자동 완성

$(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 
            } 
           })); 
          } 
         }); 
     } 
    }); 
}); 

같은 것을 사용 : https://www.googleapis.com/freebase/v1/search?query=ambrose%20b&indent=true

예 JSON

를 또한 내가 태그-이 플러그인을 사용하고 있습니다 ...

내가 노력하고 있지만 작동하지 않는 것입니다

$(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 
            } 
           })); 
          } 
         }); 
     } 
    }); 
}); 
: 작업을 수행하는 예에서
{ 
    "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 
    }..... 

답변

2

거의 옳았습니다. 입력 사항이 잘못되었으므로 다음을 시도하십시오.

$(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 
            } 
           })); 
          } 
         }); 
     } 
    }); 
});