[Developers] freebase-suggest modification
Dae Park
daepark at metaweb.com
Tue May 13 19:46:58 UTC 2008
Freebase-suggest is smart enough get around the cross-domain issue so
you shouldn't have to meddle with the logic unless your web-service
is outputting something that freebase-suggest can't parse. As long as
yous webservice looks like what the freebase search api returns
(http://code.google.com/p/freebase-suggest/wiki/FreebaseAPISearch),
you should be able to just modify the "service_url", "ac_path",
"ac_params", and "ac_qstr" options.
Your webservice response envelope (JSON) should look something like
this:
{
"status": "200 OK",
"code": "/api/status/ok",
"result": [{...},...,{...}]
}
Each individual "result" item can be in any form, however, you will
need to modify the default transform method that takes your item and
returns some html that will be appended each list item. You should be
able to specify a "transform" method in the options as well. The
transform method should takes two arguments, data and text, where
data is each item in the "result" array and text is the query string.
In summary, you should be able to do this:
$("myinput").freebaseSuggest({
"service_url": "http://somesite",
"ac_path": "/some/webservice"
"ac_params" {"some_param": "foo", "some_other_param": "bar"},
"ac_qstr": "term",
"transform": function(data, term) {
return "some html";
}
})
Depending on what html you return from your transform method, you
need to provide your own css styles.
Hope that helps.
-dae
On May 13, 2008, at 12:27 PM, Dae Park wrote:
> You should be able to $.ajax with "jsonp" as the dataType to
> accomplish what you want.
>
> -dae
>
>
> On May 13, 2008, at 11:09 AM, Zodiac Seven wrote:
>
>> This is more of a javascript question then a freebase one but
>> hoping someone here can help.
>>
>> I am trying to make a call to a webservice in freebase suggest
>> (http://code.google.com/p/freebase-suggest/)
>> This means I call a web service for every suggestion and depending
>> on that i display the suggestion.
>>
>> freebase.suggest.js Line 528.
>>
>> p.list_receive = function(input, txt, o) {//fb.log("list_receive",
>> input, query, o);
>> // handle errors
>> if (o.status !== '200 OK') {
>> fb.error("list_receive", o.code, o.messages, o);
>> return;
>> }
>> ...
>> var url = 'http://somesite/webservice?
>> callback=mycheckfunction&term=' + suggestKeyWord;
>>
>> // Create a script tag, set its src attribute and add it to the
>> document
>> // This triggers the HTTP request and submits the query
>> var script = document.createElement("script");
>> script.src = url;
>> document.body.appendChild(script);
>> ...
>> // further logic to add/remove the item
>>
>> My problem is that i'm using document.createElement("script" and
>> since that is async i have no idea of knowing the response of my
>> web service.
>> I could move the further logic into the callback but is there a
>> 'synchronous' way to wait until i get a response from my web service.
>> I can't use xmlHttpRequest because of the cross domain restriction.
>>
>> _______________________________________________
>> Developers mailing list
>> Developers at freebase.com
>> http://lists.freebase.com/mailman/listinfo/developers
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
More information about the Developers
mailing list