incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Hallett <>
Subject Re: JSONP callback param with couchdb -lucene
Date Sun, 09 Aug 2009 19:12:14 GMT
On Sun, Aug 9, 2009 at 10:24 AM, David Nolen<> wrote:
> The callback
> function must be available in the global scope for JSONP to work correctly.
> David
> On Sun, Aug 9, 2009 at 12:15 AM, Nitin Borwankar <>wrote:
>> Hi all,
>> Need some help with the cdb-luc and jQuery integration.
>> I want to transform the results format from cdb-luc to a format that my app
>> likes. I want to do that via the JSONP callback param and some jquery
>> hoop-jumping.   Am curious if the syntax is as follows or something else:-
>> .....?q=somequerytext&callback=somefuncname
>> then inside $.ajax() I would have
>> {
>>  url:  <my cdb luc url>?q=somequerytext&callback=somefuncname
>>  [....]
>>  dataType: "json",
>>  contentType: "application/json"
>>  [...]
>>  success:     somefuncname(data) { get data and transform it into something
>> recognizable to my app, do something with it } ;
>>  error:         complain(){....}
>> }
>> etc. and then the cdb-luc results will be magically stuffed into somefunc()
>> as data
>> Is this the right syntax for the ?q = part for all that to happen -
>> basically just macth the name in the callback param with the actual name in
>> the success: param in $.ajax() ?
>> Has anyone used the callback param sucessfully ?

Since it looks like you are using jQuery, the `$.getJSON` helper will
handle JSONP for you automatically.  Just pass the target URL as the
first argument, and the callback function as the third argument.  In
the URL include a `callback` parameter with a question mark as its
value. <>

    $.getJSON('<my cdb luc url>?q=somequerytext&callback=?', null,
function(data) { get data and transform it into something recognizable
to my app, do something with it });

Behind the scenes jQuery will assign your function callback to a
variable in the global namespace and will replace the question mark in
the callback parameter with the same variable name.  It will also
transform the request into a script tag instead of using

And yes, you do have the correct syntax for the URL query string.

View raw message